Giving a variable its dimensions.
When to use
When you need to set up a new variable.
Variables are "Dimensioned" (Created) using the following statement:
Dim <Name> As <Type>
- Each variable must have a unique name.
- Names should be short but descriptive
- Names cannot start with a number
- Names cannot contain any spaces or special characters (except underscores)
- The optional “Hungarian Notation” practice prefaces a name with a shorthand data type (e.g. “ws” for worksheet, “i” for integer).
Common Data Types
|Type||Use For||Assign Via|
|Integer||Numbers between -32,768 and 32,767||=|
|Long||Really large numbers (no decimals)||=|
|Double||Really large numbers (with decimals)||=|
|Objects||Object, workbook, worksheet, range, etc...||Set|
|Variant||Determined at runtime||Set or = (as req'd by true type|
Where to Create a Variable
- A variable is defined in the code above where it is needed, usually at the top of the routine.
Lesson notes are only available for subscribers.