Solved

Finding out the length of an array created using Split()

Posted on 2004-08-15
2
1,424 Views
Last Modified: 2013-12-25
Hi,

I have got a string which has a list of filenames in it separated by commas, and I have split the string into an array using the Split() function in VB6. As it happens, the string is filled with the list at run time, so I don't actually know how many items the array will have in it. Here is my code so far:

Dim thearray
Dim somestring As String
somestring = "DSC00000.JPG,DSC00001.JPG,DSC00002.JPG"
'The above line isn't actually in the code, because if it was I wouldn't have a problem. Instead, the above line would be replaced with a chunk of code to open a text file and get the contents and put them in the string.
thearray = Split(somestring, ",")

I need a way of finding out how many items are inside the array, so that I can write a loop that iterates through the array and uses each individual filename for a purpose. This should be quite a simple question to answer, and any help would really be appreciated.

Thanks
0
Comment
Question by:alexsilcock
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11805493
Private Sub Command1_Click()
    Dim thearray As Variant
    Dim somestring As String
    Dim i As Integer
   
    somestring = "DSC00000.JPG,DSC00001.JPG,DSC00002.JPG"
    thearray = Split(somestring, ",")

    For i = LBound(thearray) To UBound(thearray)
        Debug.Print thearray(i)
    Next i
End Sub
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 11807847
NumOfStrings=Ubound(thearray)+1
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question