Define a Constant

To ensure that all the title bars in a particular VBA procedure display the same text, assign the title text to a constant. By following this tip, you will save yourself the time of typing the title text more than once.

The data type of the variable valuel is String. You can check the data type easily if you follow the above instruction with this statement:

MsgBox varType(value1)

When Visual Basic runs the above line, it will display a message box with the number 8. Recall that this number represents the String data type. The next line, mySum = value1 + 2

adds 2 to the user's input and assigns the result of the calculation to the variable mySum. And because the valuel variable's data type is String, prior to using this variable's data in the computation, Visual Basic goes to work behind the scenes to perform the data type conversion. Visual Basic has the brains to understand the need for conversion. Without it, the two incompatible data types (text and number) would generate a Type Mismatch error.

The procedure ends with the MsgBox function displaying the result of the calculation and showing the user how the total was derived.

Introduction to Access 2003 VBA Programming

0 0

Post a comment