data types Flashcards
data types
not just numbers used in computations
- also texts (alphanumeric) such as names, dates, etc and logical data (true/false) also used
- data stored in different forms
numbers
integer numbers (Integer and Long)
* whole numbers used for counting (answers question “How many?”)
* two types
- Integer
▪ stored in memory locations consisting of 2 bytes (16 bits) each
▪ so are limited to the range -32,768 to 32,767
- Long
▪ stored in 4 bytes (32 bits)
▪ range from -2,147,483,648 to 2,147,483,647
** real (or decimal) numbers (Single and Double)**
* used for measuring (answers question “How much?”)
* * two types
- Single
▪ single precision numbers are stored in memory locations consisting of 4
bytes (32 bits) each
▪ approx. 7 sig figs
▪ ranges
* negative numbers: approx. -3.4E38 to -1.4E-45
* positive numbers: approx. 1.4E-45 to 3.4E38
- Double
▪ double precision numbers stored in 8 bytes
▪ approx. 15 sig figs
▪ ranges
* negative numbers: approx. -1.8E308 to -4.9E-324
* positive numbers: approx. 4.9E-324 to 1.8E308
characters (String)
sequences of characters that can be letters, numbers, punctuation marks, and spaces
▪ types
* fixed-length
- number of characters (or upper limit) is known
- can contain 1 to 65,000 characters
* variable-length
- number of characters unknown
- can contain up to 2 billion characters
Logical (Boolean) values
can take on two values
* true=1
* false = 0
▪ type of data used in If statements
type declarations
unlike most other programs, VBA lets you introduce new constants and variables without specifying type
-when undeclared variable encountered, VBA calls it Variant type
▪ will read assigned data and choose type for it depending on context
▪ if variable is later used to store different type of data, the variable type is automatically changed by
VBA
- downsides
▪ Variant type data can use more memory than declared variables
▪ when Variant type data encountered, VBA must stop and decide what kind of data storage location
is required, which slows it down (but you most likely won’t notice the performance hit)
▪ a misspelled variable name could be difficult to spot
-lack of readability – can’t easily determine appropriate data type by viewing code, so that can be problem
▪ only use when you’re uncertain of data’s type or when accommodating foreign data and you’re unsure of data type’s specifications
▪ input: Dim variable
- it’s a good idea to get into habit of declaring your variable types
the Dim statement
to declare certain data type for a variable
Dim variable1 name As type 1, variable 2 name As type 2, …
the Option Explicit statement
force the issue by placing the statement “Option Explicit” as first line in module
- if you do this, ALL variables in module MUST be declared
byte data type
VBA’s smallest numeric data type
▪ holds numeric value from 0 to 255
▪ doesn’t include negative values
currency data type
uses currency numeric data to store monetary values from -9 trillion to +9 trillion
date data type
stores specially formatted numeric value that represents both the date and time
▪ don’t have to store both date and time value
▪ date data type accepts either date or time or both
▪ ranges from January 1, 100 to December 31, 9999
decimal data type
subtype of Variant
object data type
actually a reference to an Access object such as form, report, or control