Solved

What is this error, and how to fix it

Posted on 2004-08-16
8
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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:Kiran Paul VJ
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

733 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