VB6 Editor changing case of variable names

前端 未结 10 936
迷失自我
迷失自我 2020-12-08 13:24

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 varia

相关标签:
10条回答
  • 2020-12-08 13:46

    Prevent VB6 auto correct For enum values

    As my general rule I declare constants in UPPERCASE. Since enums are essentially constants I like to declare values for enums in UPPERCASE as well. I noticed the VB6 IDE also auto corrects these.

    I found the IDE does not correct these values when using numbers and underscores '_' in the value names.

    Example:

    Public Enum myEnum
      VALUE      'Will be corrected to: Value
      VALUE1     'Will not be corrected
      VALUE_     'Will not be corrected
    End Enum   
    

    I do not know if this works in general and if this extends to naming/auto correction of variable names.

    0 讨论(0)
  • 2020-12-08 13:49

    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.

    0 讨论(0)
  • 2020-12-08 13:55

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

    0 讨论(0)
  • 2020-12-08 13:56

    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.

    0 讨论(0)
  • 2020-12-08 13:57

    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

    0 讨论(0)
  • 2020-12-08 13:58

    Close all the VB projects, open the form file with a text editor, change the case of all the names then re-open the Project with VB IDE.

    0 讨论(0)
提交回复
热议问题