Solved

What is this error, and how to fix it

Posted on 2004-08-16
8
174 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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: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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

778 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