Variable Initialization

Visual Basic automatically initializes a new variable to its default value when it is created. Numerical variables are set to zero (0), Boolean variables are initialized to False, string variables are set to the empty string (""), and Date variables are set to December 30, 1899.

Notice that the cost displayed in the message box has three decimal places. To display the cost of a calculator with two decimal places you need to use a function. VBA has special functions that allow you to change the format of data. To change the format of the cost variable you should use the Format function. This function has the following syntax:

Format(expression, format)

where expression is a value or variable you want to format and format is the type of format you want to apply.

0 0

Post a comment