Monday, May 18, 2009

For i to...

I ran into a bit of a problem yesterday. The following piece of code only returned half the values in the array, and at first I couldn't figure out why.
i = 0
for i to ubound(arrList)
strList = strList & arrList(i) & vbCrLf
i = i + 1
next

As you probably know, step 1 is the default, so that isn't written out. But if I do, my problem becomes more apparent.
i = 0
for i to ubound(arrList) step 1
strList = strList & arrList(i) & vbCrLf
i = i + 1
next

Visual Basic kindly automatically increases i with one for each run, but so do I. Remember kids, don't try this at home.

No comments: