这两天发现VBA竟然还有一个语言规范(VBA Language Specification),里面的内容算是比较深奥的。但是,感觉是很权威的资料。如果真要学好VBA,这本资料中的内容肯定还是要有所了解的。学到这个程度,能参考的中文资料已经比较有限了,到了拼英语阅读理解能力的时候了。不过,数据类型这部分相对来说已经比较熟悉了。
“Within a VBA Environment, information is represented as data values. A data value is a single element from a specific finite domain of such elements. The VBA Environment defines a variety of value types. These value types collectively define the domain of VBA data values. Each value type has unique characteristics that are defined by this specification. Each data value within a VBA Environment is a domain member of one of these value types. Individual data values are immutable. This means that there are no defined mechanisms available within a VBA Environment that can cause a data value to change into another data value. Because data values are immutable, multiple copies of a specific data value can exist within a VBA Environment and all such copies are logically the same data value.
The value types of the VBA Environment are defined by the following table. The nominal representation is the representation that was used as the original design basis for the VBA value types.
Implementations MAY use these specific data type representations to meet the requirements of this specification.”
No.
数据类型(Value Type Name)
取值范围
(Domain Elements)
表数方法
(Nominal Representation)
1
Boolean
The distinguished values True and False
16-bit signed binary 2’s complement integer whose value is either 0 (False) or -1 (True)
2
Byte
Mathematical integer in the range of 0 to 255
8-bit unsigned binary integer
3
Currency
Numbers with 4 fractional decimal digits in the range
-922,337,203,685,477.5808 to
+922,337,203,685,477.5807
64-bit signed binary two’s complement integer implicitly scaled by 10^-4
4
Date
Ordinal fractional day between the first day of the year 100 and the last day of the year 9999.
8 byte IEEE 754-1985
[IEEE754] floating point value. The floating point value 0.0 represents the epoch date/time which is midnight of December 30, 1899. Other dates are represented as a number of days before (negative values) or after (positive value) the epoch. Fractional values represent fractional days.
5
Decimal
Scaled integer numbers whose maximum integer range is
±79,228,162,514,264,337,593,543,950,335.
Number in this range may be scaled by powers of ten in the range 10^0 to 10^-28
A rational number represented in a 14 byte data structure including a sign bit and a 96-bit unsigned integer numerator. The denominator is an integral power of ten with an exponent in the range of 0 to 28 encoded in a single byte.
6
Double
All valid IEEE 754-1985 double-precision binary floating-point numbers including sized zeros, NaNs and infinities
64-bit hardware implementation of IEEE 7541985.
7
Integer
Integer numbers in the range of -32,768 to 32,767
16-bit binary two’s complement integers
8
Long
Integer numbers in the range of -2,147,483,648 to 2,147,486,647
32-bit binary two’s complement integers
9
LongLong
Integer numbers in the range of
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
64-bit binary two’s complement integers
10
Object reference
Unique identifiers of host application or program created objects and a distinguished value corresponding to the reserved identifier Nothing
Machine memory addresses with the 0 address reserved to represent Nothing.
11
Single
All valid IEEE 754-1985 single-precision binary floating-point numbers including signed zeros, NaNs and infinities
32-bit hardware implementation of IEEE 7541985.
12
String
The zero length empty string and all possible character sequences using characters from the implementation dependent character set. There MAY be an implementation defined limit to the length of such sequences but the limit SHOULD be no smaller than (216 – 1) characters.
Sequences of 16-bit binary encoded Unicode code points.
13
Empty
A single distinguished value corresponding to the reserved identifier Empty
An implementation-specific bit pattern
14
Error
Standard error codes from 0 to 65535, as well as other implementation-defined error values. An implementation-defined error value may resolve to a standard error code from 0 to 65535 in a context where its value is required, such as CInt.
32-bit integer (Windows HRESULT)
15
Null
A single distinguished value corresponding to the reserved identifier Null
An implementation specific bit pattern
16
Missing
A single distinguished value corresponding that is used to indicated that no value was passed corresponding to an explicitly declared optional parameter.
An implementation specific bit pattern
17
An Array type
Multi-dimensional numerically indexed aggregations of data values with up to 60 dimensions. Empty aggregations with no dimensions are also included in the domain. Such aggregations may be homogeneous (all elements (section 2.1.1) of the aggregation have the same value type) or heterogeneous (the value types of elements are unrelated). Elements of each dimension are identified (indexed) via a continuous sequence of signed integers. The smallest index value of a dimension is the dimension’s lower bound and the largest index value of a dimension is the dimension’s upper bound. A lower bound and an upper bound may be equal.
A linear concatenation of the aggregated data values arranged in row major order
possibly with implementation defined padding between individual data values.
18
A User-Defined Type (UDT)
Aggregations of named data values with possibly heterogeneous value types. Each UDT data value is associated with a specific named UDT declaration which serves as its value type.
A linear concatenation of the aggregated data values possibly with implementation defined padding between data values.