Tag Archives: For

Repeats a group of statements a specified number of times.

For counter [ As datatype ] = start To end [ Step step ]
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ counter ]


Do not be shy about using arrays, they are not hard to use.

   Dim people(2) As String
   people(0) = "John Henry"
   people(1) = "Catherine Weaver"
   MsgBox UBound(people)
   'access the first element in the array
   MsgBox people(0)

The split() function will make arrays to play with. For this example we are going to use split(string) and split(string, delimiter). The function returns an array of strings or string if it can not find the delimiter.

Dim myarray() as string
Dim mytext as string
Mytext = "the big red dog sat on the hill"
Myarray = split(mytext)
Dim index as integer
Index = 0
Dim output as string
Output = ""
For index to ubound(Myarray) -1
   Output = output & "index:" & index & " " & myarray(index)
Next index
Msgbox output