Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/172271

From BetaArchive Wiki

Article ID: 172271

Article Last Modified on 7/16/2004



APPLIES TO

  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • 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 Q172271

SUMMARY

You might think that you could change the letter case of a control name by changing the value of the Name property of the control in the Property Browser, or by using the Edit/Replace feature to find and replace all instances of the control name. However, the first method does not work at all if you have existing code, and the second method does not work in all cases either. This article shows you how to use a combination of methods to accomplish the change.

MORE INFORMATION

This article describes three methods to change the case of control references in code:

  • Rename the Control
  • Find and Replace
  • Temporarily Dimension a Variable

Rename the Control

This method works only if you have made no references to the control in your code. Once you make any reference in code to a control, the editor remembers the control's name and case. Changing the case of the control name after this point does not affect existing or new code.

Find and Replace

You can use the Edit/Replace feature to find and replace all instances of the control name with the new case.

NOTE: This technique does not work in every case. When you add new event procedures, the old case is used. When combined with the next technique, you can change the case of all existing and new references to the control.

Temporarily Dimension a Variable

The editor is designed so that all references to a variable name use the same case as the statement in which the variable is dimensioned.

For example, type the following inside a code window:

   Dim MyVariable as string
   myvariable = "hello"     ' is changed to MyVariable = "hello"
                

To change the letter case of a variable, you must change its letter case within the dimension statement. In the previous example, to change MyVariable to Myvariable, alter the first line to:

   Dim Myvariable as String
                

You can take advantage of this feature to change the letter case of a control's name. Just dimension a variable of the desired name and case. After you press ENTER, the case will change throughout the code window. Then simply delete the unnecessary dimension statement.

NOTE: This technique does not work in every case. It does not change the name of existing event procedure names because they are a compound name. However, new event procedure names will reflect the new case. When combined with the previous technique, you can change the case of all existing and new references to the control.

Example

The following steps show how to change the case of Command1 to command1 by using a combination of the second and third techniques:

  1. Start a new project in Visual Basic and add a command button (Command1) to the default form.
  2. Add the following line of code to the Command1_Click Event:

          Command1.Caption = "hello"
                            
  3. Change the name property of the command button from Command1 to command1. Note the code has not changed case.
  4. Add the following line of code to the Command1_Click event and press ENTER:

          Dim command1 as string
                            
  5. Note the case of the Command.Caption reference has been changed. However, the case of the event procedure name, Command1_Click, has not.
  6. Delete the line added in step 4. The change will remain in effect until another variable is dimensioned with a different case. If you leave the line in the program, you will receive an error when the program is compiled.
  7. Add a new event procedure, Command_GotFocus. Note that the new event procedure reflects the new case.
  8. You can change the case of existing event procedures manually, or you can use the Edit/Replace dialog box to search for "Sub Command1_" and replace it with "Sub command1_".



Additional query words: kbdse kbDSupport kbVBp kbVBp500 kbVBp600 kbVBp400 kbCtrl

Keywords: kbhowto KB172271