6.3. Working with Enumerations

An enumeration is a predefined list of unique integers that have individual names and meanings in a particular context. An enumeration is typically used to specify a property of an object. Each integer in the enumeration has a meaning to VBA and a name that allows you to refer to it easily. The names that correspond to the integers in the enumeration are called enumerated constants.

For example, when you use the MsgBox function to display a message box using VBA, you can use the enumerated constants in the VbMsgBoxStyle enumeration to specify the type of message box required. If you require an icon in the message box, you can specify which icon from the list of available built-in icons. For example, one of the icons — a stop sign — is the enumerated constant vbCritical or the integer 16. The enumerated constant vbQuestion or the integer 32 displays a question-mark icon and the enumerated constant vbExclamation or the integer 48 displays an exclamation-point icon. The enumerated constant vbInformation or the integer 64 refer to an information icon. The enumerated constants (names like vbQuestion) are far easier for humans to grasp, read, and remember than the values (the various integers like 16, 32, 64, and so on) to which they are mapped.

VBA includes many built-in enumerations, and the Visual Basic Editor displays the list of available enumerated constants to help you select the appropriate integer value when you're creating code. To see such a list, type this into a procedure:

msgbox("inga",

As soon as you type the comma, up pops the list of enumerated constants. If you don't see the list, choose Tools Options in the Visual Basic Editor, then select the Auto List Members check box.

You can also define your own enumerations in custom objects that you create.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.163.239