VB6 Editor changing case of variable names

Viewed 19057

I'm not much of a Visual Basic person, but I am tasked with maintaining an old VB6 app. Whenever I check out a file, the editor will replace a bunch of the uppercase variable names with lowercase automatically. How can I make this stop!? I don't want to have to change them all back, and it's a pain to have these changes show up in SourceSafe "Differences" when I'm trying to locate the REAL differences.

It is changing it automatically in the definition, too: Dim C as Control becomes Dim c as Control. Dim X& becomes Dim x&. But it doesn't do it all the time; for example, three lines down from Dim x&, there's a Dim Y&, uppercase, which it did not change. Why's it do this to me?

10 Answers

Continuing from DJ's answer...

And it won't only change the case of variables in the same scope either.

It will change the case of all variables with the same name in your entire project. So even if they're declared in uppercase in one place, another module might have different variables using the same variable names in lowercase, causing all variables in your project to change to lowercase, depending on which of the declarations was loaded (?) or edited last.

So the reason your C and X variables are changing case, while the Y isn't, is probably because C and X are declared somewhere else in your project too, but in lowercase, while Y isn't.

There's another mention of it here, where they mostly seem concerned with such variable names conflicting when case is being used to differentiate local from global variables. They end up going for prefixes instead.

The only alternative I can think of is to use some other editor with VB6-highlighting capabilities to do your editing...

Enums are even worse. Getting the case wrong anywhere the enum is used changes the case of the definition.

To get past the painful file diff experience, set the VSS option in the diff dialog to do case-insensitive comparisons. That way you'll only see the "real" changes.

It must be defined/declared in lower-case. Locate the declaration and fix it there. The IDE will always change the case to match the declaration.

I have had a similar enumeration problem where for no apparent reason UPPERCASE was changed to MixedCase.

Enum eRowDepths
    BD = 1
    CF = 1
    Separator = 1
    Header = 3
    subTotal = 2
End Enum

When I changed to the following (tailing the last character of the non-conforming variables), I had no problem

Enum eRowDepths
    BD = 1
    CF = 1
    SEPARATO = 1
    HEADE = 3
    SUBTOTA = 2
End Enum

It turns out that this is a case of the tail wagging the dog. I have the following code, not the most elegant I admit but working nonetheless (please excuse formatting issues):-

'insert 3 rows
  iSubTotalPlaceHolder = i      
  rows(ActiveSheet.Range(rangeDMirrorSubTotals).Cells.Count +  _
                                                        Header _
                                                         & ":" _
      & ActiveSheet.Range(rangeDMirrorSubTotals).Cells.Count + _
                                                      Header + _
                                                    subTotal + _
                                           Separator).Insert

So it seems that the compiler won't accept explicit UpperCase constants as part of this statement.

This was acceptable

Dim fred as Integer
fred = SEPARATO + HEADE + SUBTOTA

So my work-around is to use a variable instead of the constants as part of the complex insert statement if I want to stick to the rule of keeping enumerated constants uppercase.

I hope this is of use

DJ is spot on... VB always changes the case of variables to match the original declaration. It's a 'feature'.

Continuing from Mercator's excellent answer...

I'd recommend:

  1. Check out all files (I assume you're using VSS for a VB6 app)
  2. Do a rebuild of the entire project group
  3. Recheck back into VSS

Now base you're the real differences rather than the 'auto' changes that VB6 has tried to apply.

Related