【英文】VB的数据类型
Introduction
Notes on VB Data Types
Data Types
Variant
Primitive Types
- Numeric Types
- Integer
- Integer *
- Long
- Real Types
- Single *
- Double
- Currency
- Byte
- Integer
- String Types
- Fixed-length String (String*n)
- Variable-length String (String) *
- Boolean *
- Date *
- Numeric Types
Composite Types
- User-defined Types (Object)
- Arrays
Strings
- Strings can be fixed-length (String*n) (where n is the length of the string) or variable-length (String)
- Strings are enclosed in double quotation marks
""
- The length of a string is the number of characters in the string
- A string with a length of 0 is called an empty string and is represented by
""
Integer
- Integer consists of Integer and Long
- Integer occupies 2 bytes in memory
- Long occupies 4 bytes in memory
- Decimal numbers are composed of digits 0 to 9
- Octal numbers are composed of digits 0 to 7. To represent octal numbers, use the prefix
&
,&O
,&o
,&0
- Hexadecimal numbers are composed of digits 0 to 9 and letters A to F. To represent hexadecimal numbers, use the prefix
&H
,&h
Real Types (Floating Point Types)
- Real types consist of Single and Double
- Real numbers can be represented in two forms
- Decimal form: 3.14
- Exponential form: 0.12E+5 (0.12×105)
- Single occupies 4 bytes in memory and can represent up to 7 significant digits
- Double occupies 8 bytes in memory and can represent up to 15 significant digits
Byte
- Byte is an unsigned integer that occupies 1 byte in memory, with a value range of 0 to 255
Currency
- Currency occupies 8 bytes in memory and represents decimal numbers
- Currency is precise to 4 decimal places
Boolean
- Boolean occupies 2 bytes in memory
- Boolean can have only two values:
True
andFalse
- When a Boolean value is converted to a numeric type:
True
is converted to-1
andFalse
is converted to0
- When a numeric value is converted to a Boolean type: nonzero values are converted to
True
and0
is converted toFalse
Date
- Dates are enclosed in double pound signs
##
- Dates can represent the following ranges:
- Year, month, and day range: January 1, 100 to December 31, 9999
- Time range: 0:00:00 to 23:59:59
For example:#1 Jan,17#
,#2017-12-1 10.:30:00 am#
Variant
- Variant is the default type for variables that are not declared
Type Suffix
- Type suffixes include
%
,&
,!
,#
,$
,@
- When declaring a variable and omitting the data type, you can add a type suffix to the end of the variable name to define the data type
Variable Name with Suffix | Data Type |
---|---|
VariableName% |
Integer |
VariableName& |
Long |
VariableName! |
Single |
VariableName# |
Double |
VariableName@ |
Currency |
VariableName$ |
String |
Default Values
- When a variable with a specified data type is defined but not assigned a value, it takes on the default value
Data Type | Default Value |
---|---|
Integer | 0 |
Boolean | False |
Date | 1/1/0001 12:00:00 AM |
String | "" |
Variant | Empty |
Completion
References
Bilibili - JiaoDaYou
CSDN - fengzhou8417
CSDN - weixin_30512043