SpartaSixZero
SpartaSixZero

Reputation: 2431

How can I iterate through an array of strings using VB?

Here's my code so far:

Dim i As Integer
Dim stringArray() as String

stringArray = split("Hello|there", "|")

For i = 0 To stringArray.Length()
   ' Logic goes here
Next

VB6 doesn't seem to like me using stringAray.Length() and gives me a compile error message like Invalid Qualifier, but what's the right way to iterate through each element of a string array?

Upvotes: 11

Views: 47949

Answers (2)

Ing. Alejandro Kohen
Ing. Alejandro Kohen

Reputation: 19

Dim i As Integer
Dim stringArray() as String

stringArray = split("Hello|there", "|")

For i = 0 To ubound(stringArray)
   ' Logic goes here
Next

Upvotes: 0

Alex K.
Alex K.

Reputation: 175796

ubound() returns the upper bounds;

Dim i As Long
Dim stringArray(1) as String

stringArray(0) = "hello"
stringArray(1) = "world"

For i = 0 To ubound(stringArray)
   msgbox(stringArray(i))
Next

Upvotes: 19

Related Questions