Visual Basic 6 Data Type Reference

Visual Basic Reference Add comments

After spending a great deal of time compiling information from the MSDN and other various online and offline sources I've put together the chart you see below which details all of the different data types available in Visual Basic 6. It includes their min/max values, storage size, and other useful information such as conversion functions and a list of VbVarType constants. If you're looking for other reference material for Visual Basic I also have a VB KeyAscii Chart, a VB KeyCode Chart, and a VB KeyCode Constants Chart.

Download vb_datatype_reference.txt (July 17, 2008)

Visual Basic 6 Data Type Reference Chart

Data Type: Byte
Possible Values: 0 to 255
Storage Size: 1 byte (8 bits)
Prefix: byt
Conversion Function: Cbyte(expression)

Data Type: Boolean
Possible Values: True or False
Storage Size: 2 bytes (16 bits)
Prefix: bln
Conversion Function: Cbool(expression)

Data Type: Integer
Possible Values: -32,768 to 32,767
Storage Size: 2 bytes (16 bits)
Prefix: int
Conversion Function: Cint(expression)

Data Type: Long (long integer)
Possible Values: -2,147,483,648 to 2,147,483,647
Storage Size: 4 bytes (32 bits)
Prefix: lng
Conversion Function: CLng(expression)

Data Type: Single (single-precision floating-point)
Possible Values:
-3.402823E38 to -1.401298E-45 for negative values
1.401298E-45 to 3.402823E38 for positive values
Storage Size: 4 bytes (32 bits)
Prefix: sng
Conversion Function: CSng(expression)

Data Type: Double (double-precision floating-point)
Possible Values:
-1.79769313486231E308 to -4.94065645841247E-324 for negative values
4.94065645841247E-324 to 1.79769313486232E308 for positive values
Storage Size: 8 bytes (64 bits)
Prefix: dbl
Conversion Function: CDbl(expression)

Data Type: Currency (scaled integer)
Possible Values: -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Storage Size: 8 bytes (64 bits)
Prefix: cur
Conversion Function: Ccur(expression)

Data Type: Decimal
Possible Values:
+/-79,228,162,514,264,337,593,543,950,335 with no decimal point
+/-7.9228162514264337593543950335 with 28 places to the right of the decimal
smallest non-zero number is +/-0.0000000000000000000000000001
Storage Size: 14 bytes (112 bits)
Prefix: dec
Conversion Function: CDec(expression)

Data Type: Date
Possible Values: January 1, 100 to December 31, 9999
Storage Size: 8 bytes (64 bits)
Prefix: dtm
Conversion Function: Cdate(expression)

Data Type: Object
Possible Values: Any Object reference
Storage Size: 4 bytes (32 bits)
Prefix: obj
Conversion Function: None

Data Type: String (variable-length)
Possible Values: 0 to approximately 2 billion characters
Storage Size: 10 bytes (80 bits) + string length
Prefix: str
Conversion Function: CStr(expression)
Notes: Use the StrConv function to convert one type of string data to another.
StrConv Usage: StrConv(String, Conversion As VbStrConv, [LocaleID As Long])

Data Type: String (fixed-length)
Possible Values: 1 to approximately 65,400
Storage Size: Length of string
Prefix: str
Conversion Function: CStr(expression)
Notes: Use the StrConv function to convert one type of string data to another.
StrConv Usage: StrConv(String, Conversion As VbStrConv, [LocaleID As Long])

Data Type: Variant (with numbers)
Possible Values: Any numeric value up to the range of a Double
Storage Size: 16 bytes (128 bits)
Prefix: vnt
ConversionFunction: Cvar(expression)

Data Type: Variant (with characters)
Possible Values: Same range as for variable-length String
Storage Size: 22 bytes (176 bits) + string length
Prefix: vnt
ConversionFunction: Cvar(expression)

Data Type: User Defined Type
Possible Values: The range of each element is the same as the range of its data type.
Storage Size: Number required by elements
Prefix: udt
ConversionFunction: None

Notes:
======
Arrays of any data type require 20 bytes of memory plus 4 bytes for each
array dimension plus the number of bytes occupied by the data itself. The
memory occupied by the data can be calculated by multiplying the number
of data elements by the size of each element. For example, the data in a
single-dimension array consisting of 4 Integer data elements of 2 bytes
each occupies 8 bytes. The 8 bytes required for the data plus the 24 bytes
of overhead brings the total memory requirement for the array to 32 bytes.

A Variant containing an array requires 12 bytes more than the array alone.

Type Declaration Characters Reference Chart
===========================================
Data Type  Character   Example     Equivalent To
---------  ---------   --------    -------------
Currency   @           Dim var@    Dim var As Currency
Double     #           Dim var#    Dim var As Double
Integer    %           Dim var%    Dim var As Integer
Long       &           Dim var&    Dim var As Long
Single     !           Dim var!    Dim var As Single
String     $           Dim var$    Dim var As String

VB Type Conversion Functions Reference Chart
============================================
Function Name      Converts an expression to   Notes
*************      *************************   *****
CBool(expression)  a Boolean value             expression can be any valid string or numeric expression.
CByte(expression)  a Byte value                expression must be between 0 and 255
CCur(expression)   a Currency value            expression must be a numeric value between -922,337,203,685,477.5808 and 922,337,203,685,477.5807
CDate(expression)  a Date value                expression must be a valid date expression
CDbl(expression)   a Double value              expression must be a numeric value between -1.79769313486232E308 and -4.94065645841247E-324 for negative values, or between 4.94065645841247E-324 and 1.79769313486232E308 for positive values.
CDec(expression)   a Decimal value             expression must be a numeric value of +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers (numbers with no decimal places), or +/-7.9228162514264337593543950335 for numbers with 28 decimal places.
CInt(expression)   a Integer value             expression must be a numeric value from -32,768 to 32,767. Fractions are rounded.
CLng(expression)   a Long value                expression must be a numeric value from -2,147,483,648 to 2,147,483,647. Fractions are rounded.
CSng(expression)   a Single value              expression must be a numeric value from -3.402823E38 to -1.401298E-45 for negative values, or from 1.401298E-45 to 3.402823E38 for positive values.
CStr(expression)   a String value              a null expression value will cause a runtime error.
CVar(expression)   a Variant value             expression can be either numeric or a string.
CVDate(expression) a Variant of subtype Date   expression must be a valid date expression
CVErr(errornumber) a Variant of subtype Error  contains the error number specified by the errornumber argument.

Other Useful Conversion Functions
=================================
Function Name          Description
*************          ***********
Error([ErrorNumber])   Returns the error message for a given error number.
Error$([ErrorNumber])  Returns the error message for a given error number.
Fix(Number)            Returns the integer portion of a number
Hex(Number)            Returns a string representing the hexadecimal value of a number
Hex$(Number)           Returns a string representing the hexadecimal value of a number
Int(Number)            Returns the integer portion of a number
Oct(Number)            Returns a string representing the octal value of a number
Oct$(Number)           Returns a string representing the octal value of a number
Str(Number)            Returns a string representation of a number
Str$(Number)           Returns a string representation of a number
Val(String)            Returns a double representing the value of the numbers contained in the string

Notes on built-in VB IsNumeric() Function
=========================================
Function IsNumeric(Expression) As Boolean
Member of the VBA.Information Class
Returns True if an expression can be evaluated as a number

Useful tidbit on variable declaration:
======================================
When declaring multiple variables, such as:
Dim i, j As Integer

Only j is declared as an integer. i is declared as a Variant (the default).
If you want both to be integers you should say:

Dim i As Integer, j As Integer

VBA.VbVarType Constants
=======================
Name               Actual VB Definition
****               ********************
vbArray            Const vbArray = 8192 (&H2000)
vbBoolean          Const vbBoolean = 11
vbByte             Const vbByte = 17 (&H11)
vbCurrency         Const vbCurrency = 6
vbDataObject       Const vbDataObject = 13
vbDate             Const vbDate = 7
vbDecimal          Const vbDecimal = 14
vbDouble           Const vbDouble = 5
vbEmpty            Const vbEmpty = 0
vbError            Const vbError = 10
vbInteger          Const vbInteger = 2
vbLong             Const vbLong = 3
vbNull             Const vbNull = 1
vbOject            Const vbObject = 9
vbSingle           Const vbSingle = 4
vbString           Const vbString = 8
vbUserDefinedType  Const vbUserDefinedType = 36 (&H24)
vbVariant          Const vbVariant = 12
==========================================================================

MSDN Links
 Data Type Summary (Visual Basic 6)
 Data Types Overview (Visual Basic 6)

Leave a Comment

Entries RSS Comments RSS Log in