Bug: Forcing single-letter variable uppercase

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I think that this problem started with v.1.8 and has continued in 1.9.

The app I'm working on is a very large one (over 12,000 lines of code) and of course it uses some single-letter variables in it, normally as local variables but sometimes passed in calling Subs.

I always make these variables lowercase, such as Dim i, j as Int, but every once in a while, a letter will turn uppercase throughout the code. I can do a global replace to get it back to lowercase, but after a while, I'll notice that some other letter has turned uppercase.

This doesn't affect the execution of the code of course, but it is a nuisance and distraction, so it would be nice to get this fixed.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
I don't know how it would be possible to reproduce it at will. At this point I'm test-running the app and changing a line or two when needed, but it's never anything that would affect or cause this problem. For example, the last instance was the letter "a" changing to uppercase throughout the code. I'm pretty sure that I didn't change any lines with "a" in them and I'm certain that I have never put an uppercase "a" in the code.

The "a" changed only where it is used as a variable, not in strings or in code comments.

I was just working and noticed that the "a" was uppercase everywhere now. This is the first time it's been an "a". Before that, it was "s" that changed and before that, "p" changed, I changed it back, and it changed again. This happened at least 3 times with "p".

I've used a lot of other single-character variables which have NOT changed, so it's not like I can just add a variable and watch it change, which is why I don't see how to reproduce it.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Okay, here's a little more strangeness:

I found a Dim A, d, tb As String (where the "a" had changed to "A") in a sub.

When I change "A" to "a", I can see it change throughout the Sub. I change it back to "A" and it changes throughout the sub again -- immediately, as soon as I type it. The same thing happens when changing "d" to/from "D".

When I changed "tb" to "TB", it changed in the sub, but when I changed it from "TB" to "Tb", not only did it not change, but "Tb" turned red (the color I use for UndeclaredIdentifier) in the Dim line and "TB" turned red in the sub. When I changed "Tb" to "tb", the code throughout the sub also changed and it was no longer red. Then when I went from "tb" to "Tb", this time it did NOT turn red. Then I went from "Tb" to "TB" - not red; back to "Tb" - not red. I could no longer make it turn red again.

I changed it back to "Dim a, d, tb As String" and then changed "d" to "D". This made "tb" turn red on the Dim line and throughout the Sub.

Even though all the instances of a single-letter variable in the entire code changed at the same time, changing the Dim in a sub back to lowercase only changes that sub.
 

corwin42

Expert
Licensed User
Longtime User
I can confirm this problem and I too don't know how to reproduce it.

I often use "for i = 0 to...". Sometimes the small "i" changes to uppercase for all "for"-loops in a complete code module.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Wow. This turned out to be easier to reproduce than I thought.

Just make an app with the code below. Change any Dim variable to uppercase, it changes the other instance of the variable. The same is true of the "g" in Sub blah(g as Int).

If this is an intended feature, I don't remember seeing this happen before 1.8 and it would seem that the variables changing on their own would have to be related to this feature. If it is not an intended feature, then there's your bug.

To reiterate, the bug is not just a variable changing case in one sub, but throughout the entire project, even when the variable is only Dim'd locally. (I never Dim a one-letter variable in Globals. The "k" below was just for illustration.)

B4X:
Sub Globals
   Dim k As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim i, j As Int
   Dim s, s2 As String
   
   i = 1
   j = 2
   s = "a"
   s2 = "b"
End Sub

Sub blah(g As Int)
   k = g
End Sub
 
Last edited:

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Erel - Are you looking into this bug, or did you still need some input from me?

FWIW, I did a global replace to lowercase all the single-character uppercase variables 5 days ago and none of them have turned back into uppercase again even though I have worked on the program a lot every day since then.

Also, I don't think that I mentioned before that in the code, I have

B4X:
Dim i As Int
For i = ...

and in some places, if I change the Dim i to Dim I, the i in the next line will change to I and in other places, it does not. This happens with other single-character variables too, not just i.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
While you're making this change, here is a related wish:

Just as using a color scheme in which UndeclaredIdentifiers are in red makes it easy to spot variables which have not been Dim'd,
it would be equally of value if any variables which have been Dim'd but not used were also displayed in red (or the user's color choice).

Example: Dim i, j, k, x, y, z As Int
where x was never used.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
While you're making this change, here is a related wish:

Just as using a color scheme in which UndeclaredIdentifiers are in red makes it easy to spot variables which have not been Dim'd,
it would be equally of value if any variables which have been Dim'd but not used were also displayed in red (or the user's color choice).

Example: Dim i, j, k, x, y, z As Int
where x was never used.

I saw a work-around for this in this later thread, but it would still be nice to have it work as described above so that unused variables could be spotted more easily without having to search for each variable in every Dim statement.
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
...I always make these variables lowercase, such as Dim i, j as Int, but every once in a while, a letter will turn uppercase throughout the code. I can do a global replace to get it back to lowercase, but after a while, I'll notice that some other letter has turned uppercase....

I had hoped that this would be fixed in 1.92, but it is still happening. As you can see in the attached, I have "Dim t As Int" but it stays "T" on the next line. If I change that line to "t", it immediately changes back to "T".
 

Attachments

  • dim t.jpg
    dim t.jpg
    9.2 KB · Views: 213
Top