Solved

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

Posted on 2004-08-15
2
1,413 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now