Microsoft KB Archive/161232

= How To Use Spaces in Enumerated Types =

Article ID: 161232

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q161232



SUMMARY
Beginning with version 5.0, Visual Basic supports Enumerated Types. Enumerations provide a convenient way to work with sets of related constants and to associate constant values with identifiers. The identifier may be defined as either a normal identifier or a more "friendly" identifier that can contain spaces.

NOTE: Other identifiers, such as variable names and procedure names, can not contain spaces.



MORE INFORMATION
 Start Microsoft Visual Basic version 5.0. Create a new Standard EXE. Form1 is created by default. Add a CommandButton, Command1, to Form 1.  Add the following code to Form1: Enum Keys1 TabKey = 12 EnterKey = 13 SpaceBar = 32 End Enum

Enum Keys2 [Tab Key] = 12 [Enter Key] = 13 [Space Bar] = 32 End Enum

Private Sub Command1_Click Dim i As Long i = Keys1.EnterKey MsgBox i         i = Keys2.[Space Bar] MsgBox i     End Sub  Run the project. Note that the brackets are required or an error will occur. Though the brackets will not be displayed when Visual Basic displays a drop list of the members of the enumeration. Such as, when you type a period after "Keys2", Visual Basic displays a drop list showing the members of the Keys2 enumeration without the brackets:

Enter Key

Space Bar

Tab Key

When you select one of the members, Visual Basic fills in the brackets for you.

This code will generate a Compile Error on the second "Test2" line. This is due to the compiler expecting an end-of-statement after the word "Space."

