I want to define variables in a loop. Something as below.
Dim ctr as integer
for ctr=1 to 10
dim MyVar<value of ctr>
' which will be like MyVar1...MyVar10
next
Can this be done ?
Printable View
I want to define variables in a loop. Something as below.
Dim ctr as integer
for ctr=1 to 10
dim MyVar<value of ctr>
' which will be like MyVar1...MyVar10
next
Can this be done ?
No. When you use Dim to declare a variable, that variable ceases to exist once the current block, in your case the current iteration of the For loop, completes. Try using an array or a collection. That's what they're for:VB Code:
Dim ctr As Integer = 10 Dim myVars(ctr - 1) As Object
Thanx a lot.