Dim Identifier [As Datatype] If you omit the optional data type, the variable’s type defaults to variant. It is best to always declared the type, even when you intend to use variants. Dim Statement Examples – Dim strCustomerName As String As Integer Dim intTotalSold As Single Dim sngTemperature Dim curPrice As Currency Dim vntChanging to Variant type ‘Defaults Dim The reserved word is really for dimension, which means When you declared a variable, the “size.” amount of memory reserved depends on its data type. Table below show the amount of memory allocated for each data type. Note: Visual Basic does not require you to declare a variable before using it. Data Type Number of of Memory Allocated Boolean 2 1 Byte Currency 8 Date 8 Double 8 Integer 2 Long 4 Single 4 String (variable length) 10 bytes plus 1 byte for each character in the string. Variant Holding numbers 16 bytes. – Holding characters 22 bytes plus 1 byte for each – character in the string Entering Dim Statements
Dim Identifier [As Datatype] If you omit the optional data type, the variable’s type defaults to variant. It is best to always declared the type, even when you intend to use variants. Dim Statement – Examples Dim strCustomerName As String Dim intTotalSold As Integer Dim sngTemperature As Single Dim curPrice As Currency Dim vntChanging ‘Defaults to Variant type The reserved word Dim is really for dimension, which means “size.” When you declared a variable, the amount of memory reserved depends on its data type. Table below show the amount of memory allocated for each data type. Note: Visual Basic does not require you to declare a variable before using it. Data Type Number of of Memory Allocated Boolean 2 Byte 1 Currency 8 Date 8 Double 8 Integer 2 Long 4 Single 4 String (variable length) 10 bytes plus 1 byte for each character in the string. Variant Holding numbers – 16 bytes. Holding characters – 22 bytes plus 1 byte for each character in the string Entering Dim Statements