Link to home
Start Free TrialLog in
Avatar of andyakira
andyakira

asked on

What is this error, and how to fix it

Compile Error:
for control variable already in use

Highlights "For i = 1 To"

it has worked before- any suggestions
Avatar of Burbble
Burbble
Flag of United States of America image

Could you post the entire code please?

>> Highlights "For i = 1 To"

"For i = 1 to" is incomplete. You need a number after the "to". For example:

For i = 1 to 10
    DoEvents
Next i

From the error you describe, it sounds like you are using the same variable for two For/Next loops nested within each other, like this:

For i = 1 to 10
    For i = 1 to 10
        DoEvents
    Next i
Next i

You need to use a different variable for each nested For/Next loop.

Without your code I can't help any more :-)

-Burbble
Avatar of petoskey-001
petoskey-001

Your nesting your loops.  For instance this will cause it...

For i = 1 to 100
    'do something
     For i = 100 to 200
         'do something else
           
The compiler can't use i because it's already in use by the for loop
Avatar of andyakira

ASKER

    For i = 1 To Login.access.ListItems.Count
            NBuf = NBuf & Login.access.ListItems(i) & " X "
            If (Login.access.ListItems.Count Mod 5) = 0 Then
                If frmLogin.WhisperBack.Value = 1 Then
                    Send "?msg " & strAccount & " " & NameBuf
                Else
                    Send NBuf
                End If
                NBuf = ""
            End If
            Wait (2)
        Next i
       
i got it to working, i had alot of those for/loops in there, and i missed a next :( TY ALL
anywhos is there a way to split the points to both u guys? since you both helped me look in the right direction.
Avatar of Kiran Paul VJ
hi..

try this

Dim temp

temp =   Login.access.ListItems.Count
   For i = 1 To temp
  ...
  ...
  ...
 Next i

Also plz chk if the temp is getting correct value
by MsgBox temp or Debug.print temp

Also Please chk if you have Declared i as Global

kiranvj
ASKER CERTIFIED SOLUTION
Avatar of petoskey-001
petoskey-001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad we could help, but why did you select the above answer?

You may want to post a question in https://www.experts-exchange.com/Community_Support/ asking to "unaccept" the answer so you can select the correct one.

There is a "Split Points" link above the "Post a Comment" box at the bottom when the question is open.

-Burbble