Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Understanding Scope and Variables - Pg. 155

Using Visual Basic to Automate Your Database 3. 155 On the Editor tab of the Options dialog box, select the option Require Variable Declaration, and then click OK. The HelloWorld5 database has this option selected already. Choosing the Data Type for a Variable Like a field in a table, a variable has a data type. The variable int Answer in the Import procedure is declared as an Integer. (You might remember that Integer is one of the values you can choose as the field size for a field with the Number data type.) Many of the field data types have a corresponding data type that you use for a variable in a program. Table 5-1 lists field data types and the corre- sponding data type that you would use when creating a variable. Table 5-1. Field and Variable Data Types Field Data Type Text Number Currency Yes/No Date/Time Corresponding Variable Data Type String Integer, Long, Double, or Single Currency Boolean Date If you do not specify a data type when you declare a variable, the variable uses the data type Variant, a Visual Basic data type that can store any type of data. The Variant data type requires more space in memory than other data types because it's not specific. You can minimize the memory required for a variable by declaring the specific type of data that the variable will hold. Although you should avoid using Variant whenever possible, you'll need to use it when you want a variable to store different types of data at different times and in circumstances in which you're handling Null and