PDA

View Full Version : Quirk the For..Next Statement counter variable



tdm100
09-25-2006, 02:14 AM
When I type the counter variable of For..Next Statement I usually do so in the Lowercase.
Occasionally, and the frequency of this occurrence has increased as of late, the darn thing automatically gets changed to the Uppercase.
And once it does, there is no way in heck to get it back to the Lowercase.

'Excel 2000

'For example
Stuff = Split(Stuff2do, "%")
For n = 0 To UBound(Stuff)
Debug.Print Stuff(n)
Next n

'will soon be

Stuff = Split(Stuff2do, "%")
For N = 0 To UBound(Stuff)
Debug.Print Stuff(N)
Next N


I can go for days without it occurring, then all of a sudden it starts up again.
It's a matter of annoyance more than anything else.
For it doesn't interrupt or disrupt the code in any way.

I would like to know what's causing it and if it is correctable.

It usually does it for the single character "n" but it has done it for other single characters as well such as "i".
But "n" is the instigator and then the other single character counter variables join in and wanna be Uppercase too.

So far I've noticed, it hasn't done it for counter variable characters > 1.

Also, it's not immediate.
The workbook the code is in can be run, saved & closed, and remain lowercase, then BOOM, outta nowhere insists on being Uppercase.

Once it has changed to Uppercase, any attempts at changing it back to Lowercase is met with resistance and immediate!
It don't wanna be Lowercase no more!

mdmackillop
09-25-2006, 05:54 AM
If you declared your variable, it will appear in all instances exactly as declared. In this case

Dim n as long

This is useful when typing longer variable as the "correction" will not occur if the variable is wrongly typed
eg

Dim IsThisProperCase As Boolean
MsgBox issthispropercase
MsgBox IsThisProperCase

Cyberdude
09-25-2006, 08:43 PM
I strongly agree. Save yourself a lot of grief by using the following statement at the top of your VBA module:

Option Explicit

Then, if you are tempted to not dimension a variable, VBA will remind you.

Jacob Hilderbrand
09-25-2006, 09:09 PM
This anomaly occurs when not using Option Explicit at the top of your code. :whip