Solved

What is this error, and how to fix it

Posted on 2004-08-16
8
172 Views
Last Modified: 2010-05-02
Compile Error:
for control variable already in use

Highlights "For i = 1 To"

it has worked before- any suggestions
0
Comment
Question by:andyakira
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:Burbble
ID: 11817579
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
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 11817586
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
0
 

Author Comment

by:andyakira
ID: 11817595
    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
       
0
 

Author Comment

by:andyakira
ID: 11817626
i got it to working, i had alot of those for/loops in there, and i missed a next :( TY ALL
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:andyakira
ID: 11817629
anywhos is there a way to split the points to both u guys? since you both helped me look in the right direction.
0
 
LVL 16

Expert Comment

by:kiranvj
ID: 11817633
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
0
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 100 total points
ID: 11817686
I know there are ways to split points.  I think it's called an assisted answer.  I don't remember what it looks like, but that's what you would search for in the help section.
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11823760
Glad we could help, but why did you select the above answer?

You may want to post a question in http://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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 47
vb6 connector to mongodb 2 53
Macro Excel - Multiple If conditions 2 65
Problem to With line 4 43
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now