Some discussions on variable data types (i)

Source: Internet
Author: User
Tags integer variables
Variables | data | Data type Variant variables are formatted with OLE definitions, can hold any type of data, and the format of the following diagram holds some variables in 16 bytes.

0-1
2-7
8-15

VarType
Unused
Value


The No. 0 and 1 bytes hold an integer value to indicate what type of data is stored in the 第8-15 byte, and the 2nd to 7th byte is generally not used, and in most cases the 8th to 15th byte of the variable is not fully used. For example, if you save an integer with a Variant variable, the value in the first two bytes is 2-vbinteger, and the 8th and 9 bytes hold the real 16-bit value.

Let's write a piece of code to verify that.

The Dim V As Variant is the default data type for VB, so it can also be defined as Dim V

v=1000

Debug.Print VarType (v) ' Output results 2–vbinteger

Another way to test:

Private Declare Sub copymemory Lib "kernel32" Alias "RtlMoveMemory" (destination as any, Source as any, ByVal Length as Lo Ng



Dim V as Variant

Dim I as Integer

v = 1000

CopyMemory I, V, 2

Debug.Print "0-1-bit is" & I

CopyMemory I, ByVal (VarPtr (v) + 8), 2

Debug.Print "8-9-bit is" & I

You can see that the 8-9-bit result is 1000, and 0-1 bits are 2-vbinteger.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.