Microsoft Office Tutorials and References
In Depth Information
Figure 5-1. Example message box
In the first line, the code MsgBox("Proceed?", vbOKCancel) causes Excel to display a
message box with an OK button and a Cancel button and the message "Proceed?", as shown in
Figure 5-1 .
Figure 5-1. Example message box
If the user clicks the OK button, Excel will return the constant value vbOK ; otherwise it will return
the value vbCancel . Thus, the If statement in the first line will distinguish between the two
responses. (We will discuss the If statement in detail in Chapter 8 . Here, we are interested in the
role of symbolic constants.)
In case you are not yet convinced of the value of symbolic constants, consider the following enum
for color constants:
Enum ColorConstants
vbBlack = 0
vbBlue = 16711680
vbMagenta = 16711935
vbCyan = 16776960
vbWhite = 16777215
vbRed = 255
vbGreen = 65280
vbYellow = 65535
End Enum
Consider which you'd rather type, this:
ATextBox.ForeColor = vbBlue
or this:
ATextBox.ForeColor = 16711680
Need I say more?
5.4 Variables and Data Types
A variable can be thought of as a memory location that can hold values of a specific type. The
value in a variable may change during the life of the program—hence the name variable.
In VBA, each variable has a specific data type , which indicates which type of data it may hold.
For instance, a variable that holds text strings has a String data type and is called a string variable .
A variable that holds integers (whole numbers) has an Integer data type and is called an integer
 
 
Search JabSto ::




Custom Search