Dim i As Int: i is auto-capitalized

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I noticed in version 2.70 that if I write a statement such as:

B4X:
Dim i As Int
i = 10

The variable i will be automatically capitalized to become:

B4X:
Dim I As Int
I = 10

I remember this happened in some earlier version, then was fixed in an update. It now seems to have reappeared.

Is there something that I am doing that causes this?

Here is a snippet from actual code:

B4X:
Sub UpdhsvIPics(lst As List)
  Dim I, j, k As Int
  Dim s As String
     
  j = hsvIPics.Height * 0.8
     
  For I=0 To lst.Size-1
    s = lst.Get(I)
    ...

The variable I started out as lowercase. I became uppercase although j and k remained lowercase. In the for loop i was changed to uppercase.


Thanks,
Barry.
 
Last edited:

nicholas.jj.taylor

Member
Licensed User
Longtime User
This is very interesting to discover, thank you.

I would have never noticed this myself as I prefix all variable with a letter code to denote their type eg. i would be IntI (although I tend to use IntIdx, or something more meaningful).

These come from using VB.Net too much. Its a standard convention in that.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I is capitilized

I think this is because you are declaring I as Int in capital

when you are using a for loop you don't need to declare the variable
try it, delete the dim I statement and you will see that the i remains lower case and your code will still work.

Regards,
Walter
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
when you are using a for loop you don't need to declare the variable
Regards,
Walter

Interesting. I did not know you did not need to declare the for–loop variable.

I added my small example to a different program (without the for–loop changes). After several exits, reopens, and test compiles the variable I was not being auto–capitalized.

In my other program, even though I change I back to lowercase it is auto-capitalized again.

Don't know what triggers it.

I use I as a local, temporary, Int value in more places than just the for loop, but not having to declare the loop variable specifically will be handy.

Barry.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
...when you are using a for loop you don't need to declare the variable
try it, delete the dim I statement and you will see that the i remains lower case and your code will still work...

although technically this is correct, this should be discouraged! the reason is variables that are not Dim'd as a specific type are created as variants, which are stored as strings, and processing them to different types slows down your app. variants are the slowest variable types. Int's are the fastest. Don't use variants unless you absolutely have to!

@canalrun, your code will run much faster if you stick to specific variable types. try it and see for yourself. I just tried 'dim i as int' and it did not capitalize the 'i'. If the I is capitalized in the Dim statement, even in another place in your code, it will always be displayed as I instead of i. This was a request long ago to mimic the behavior of vb6, so you could use myNewOnlineAppGlobalVariable once in a Dim statement, then every time you entered it again, it didn't matter if you capitalized it, the editor would correct the capitalization to that in the Dim statement. Hope this helps...
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
although technically this is correct

your code will run much faster if you stick to specific variable types.

even in another place in your code, it will be displayed as I instead of i

Thanks for your input. I will stick to dimmed ints for loop variables.

I went back to my code, a rather large program, and tried changing the uppercase I's to lowercase i's. What I found agrees with your statement: if an uppercase I was dimmed or used as the loop variable in a for loop further down in a subroutine it would remain capitalized until I changed the occurrences further down. Then I could change it to lowercase.

This is making sense now.

Barry.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
...variables that are not Dim'd as a specific type are created as variants ... variants are the slowest variable types...

Erel, I am glad to see the new compiler warnings are pointing this out. Thank you.
 
Upvote 0
Top