Solved

What is this error, and how to fix it

Posted on 2004-08-16
8
171 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

13 Experts available now in Live!

Get 1:1 Help Now