What Is a Variable

A variable is a name used to refer to an item of data. Each time you want to remember a result of a VBA instruction, think of a name that will represent it. For example, if you want to keep track of the number of controls on a particular form, you can make up a name such as NumOfControls, TotalControls, or FormsControlCount.

The names of variables can contain characters, numbers, and some punctuation marks except for the following: , # $ % & @ !

The name of a variable cannot begin with a number or contain a space. If you want the name of the variable to include more than one word, use the underscore (_). Although a variable name can contain as many as 254 characters, it's best to use short and simple names. Using short names will save you typing time when you need to reuse the variable in your Visual Basic procedure. Visual Basic doesn't care whether you use uppercase or lowercase letters in variable names; however, most programmers use lowercase letters. When the variable name is comprised of more than one word, most programmers capitalize the first letter of each word, as in the following: NumOfControls, First_Name.

Introduction to Access 2003 VBA Programming

0 0

Post a comment