Variable Declarations

After adding and renaming the class module, the next step is to declare the variables that will hold the data you want to store in the object. Each item of data you want to store in an object should be assigned a variable. Class variables are called data members and are declared with the Private keyword. This keyword ensures that the variables will be available only within the class module. Using the Private keyword instead of the familiar Dim statement hides the data members and prevents other parts of the application from referencing them. Only the procedures within the class module in which the variables were defined can modify the value of these variables.

Because the name of a variable also serves as a property name, use meaningful names for your object's data members. It's traditional to preface the variable names with m_ to indicate that they are data members of a class.

1. Type the following declaration lines at the top of the CEmployee class module:

Option Explicit 'declarations

Private m_LastName As String Private m_FirstName As String Private m_Salary As Currency Private m_Id As String

Notice that the name of each data member variable begins with the prefix "m_".

0 0

Post a comment