Microsoft KB Archive/129712

= PRB: Capitalization in Visual Basic 4.0 Differs from 3.0 =

Article ID: 129712

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129712



SYMPTOMS
Variable case is persistent after the first reference of the variable has been set.



CAUSE
This happens because Visual Basic maintains a single name table for the entire project where all names that are not case-sensitive are stored as a single entry. This forces all occurrences of the same name, regardless of where it is used (Sub procedure, parameter, dim, type, or whatever), to be treated the same.

The names are based on where they are declared. The case of the name in the last Declare statement always wins. Each name is tagged in the name table with whether or not it has a corresponding Declare statement. If it does, any access to the name from a statement that is not a Declare statement causes the new name to have the same case as the name in the name table.



STATUS
This behavior is by design. This design brings Visual Basic for Windows behavior more in line with the embedded version of Visual Basic, Applications Edition in Excel and other Microsoft products.



MORE INFORMATION
Variable case in form files (.FRM) and modules (.BAS) in Visual Basic version 4.0 is handled differently from the way it was handled in version 3.0.

In Visual Basic for Windows version 3.0, the case of your variables was decided by the most recent line parsed by the environment containing the variable.

This behavior changed in Visual Basic version 4.0. When you first define a variable either by explicitly declaring it or implicitly by referencing the variable in a line that gets parsed (assuming Option Explicit is not enforced), that is the case that will be used throughout your program.

This occurs for all variables in scope at the line where the variable name is referenced.

Steps to Reproduce Behavior
In Visual Basic version 3.0:

 Start a new project in Visual Basic. Form1 is created by default.  Add the following code to the Form1_Click procedure: Dim MYVAR 'This creates a variable name in all Caps.

myvar = 3 'This changes BOTH instances of the variable name to lower case.   Note that the following is the final result:   Dim myvar myvar = 3 

In Visual Basic version 4.0:

 Start a new project in Visual Basic. Form1 is created by default.</li>  Add the following code to the Form1_Click procedure: Dim MVAR 'This creates a variable name in all caps.

MyVar = 3 'This variable name is changed to match the case of the original 'reference. </li>  Note that the following is the final result: <pre class="fixed_text">  Dim MYVAR MYVAR = 3 </li></ol>

Additional query words: 4.00 case sensitivity insensitive insensitivity vb4win vb4all

Keywords: kbprb KB129712

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.