ANUNEZ
10-08-2001, 02:13 PM
I tried to create nested loop using an array, but I get the error variable in use. I guess I should not get this error because i'm making reference to an array. please help:
Sub test()
Dim xx(1 To 2) As Integer
For xx(1) = 1 To 10
For xx(2) = 12 To 20
MsgBox xx(1) + xx(2)
Next xx(2)
Next xx(1)
End Sub
Squirm
10-08-2001, 02:18 PM
It's very simple, you can't use Booleans or Array elements in a For statement... simple:
Numeric variable used as a loop counter. The variable can't be a Boolean or an array element.
ANUNEZ
10-08-2001, 02:22 PM
Thanks. That's going to be an issue because I need to use something like arrays in a nested loop.
I want to do something like the code below, but replace the position variable with an array.
For position1 = Start(1) To Limit(1)
For position2 = Start(2) To Limit(2)
For position3 = Start(3) To Limit(3)
For position4 = Start(4) To Limit(4)
For position5 = Start(5) To Limit(5)
For position6 = Start(6) To Limit(6)
For position7 = Start(7) To Limit(7)
rst.AddNew
rst(0) = Chr(position1) & _
Chr(position2) & _
Chr(position3) & _
Chr(position4) & _
Chr(position5) & _
Chr(position6) & _
Chr(position7)
rst.Update
Next position7
Next position6
Next position5
Next position4
Next position3
Next position2
Next position1
ANUNEZ
10-08-2001, 02:31 PM
By the way,
I just checked the help file and it says the exact thing you told me, but why does this code work?
Dim xx(1) As Integer
For xx(1) = 0 To 5
MsgBox xx(1)
Next xx(1)
Please explain
anhmytran
10-08-2001, 03:05 PM
You are right, both codes work:
Dim x1 As Integer
For x1 = 0 To 5
MsgBox x1
Next x1
Dim xx(1) As Integer
For xx(1) = 0 To 5
MsgBox xx(1)
Next xx(1)
I just wondew why do you want the hard way?
AnhMy_Tran
Volte
10-08-2001, 04:26 PM
you could use this instead: <pre><font color=blue>Sub</font color=blue> test()
<font color=blue>Dim</font color=blue> i <font color=blue>as Integer</font color=blue>, j <font color=blue>as Integer</font color=blue>
<font color=blue>Dim</font color=blue> xx(1 To 2)<font color=blue>As Integer</font color=blue>
<font color=blue>For</font color=blue> i = 1 To 10
<font color=blue>For</font color=blue> j = 12 To 20
xx(1)= i
xx(2)= j
MsgBox xx(1)+ xx(2)
<font color=blue>Next</font color=blue> j
<font color=blue>Next</font color=blue> i
<font color=blue>End Sub</font color=blue></pre>
If at first, you don't succed, call it version 1.0.