2.1. Data Types


Table 2-1 lists the data types supported by VB 2005 and their counterparts in VB 6. If the size of a VB 6 type differs from that of its corresponding VB 2005 type, its size in bytes is shown in parentheses. For example, the Currency type (which takes up 8 bytes) in VB 6 is replaced in VB 2005 by the Decimal type. The old Decimal type (which takes up 12 bytes in VB 6), is now 16 bytes. Integer is now 4 bytes, instead of its 2 bytes in VB 6. Likewise, the Long data type is now 8 bytes, instead of its 4 bytes in VB 6.

VB 6 Tip: The venerable VB 6 Variant data type in VB 6 is no longer supported in VB 2005; you should use the Object type instead. Object and the types that derive from it are discussed at greater length in Chapter 3.


Intrinsic and User-Defined Types

VB 6 and VB 2005 support two types of intrinsic data types and user-defined types. Intrinsic data types are those types that are built into the language. Examples of intrinsic data types are Integer, Short, and Char. User-defined types (UDT), on the other hand, are data types defined by programmers. Examples of user-defined data types are classes and structures. Most of the data types discussed in this chapter are intrinsic data types; Chapter 3 will discuss user-defined data types in more detail.


Table 2-1. Data types in VB 2005

VB 2005 type

Size (bytes)

VB 6 type (size in bytes)

Boolean

Depends on implementing platform

Boolean

Byte

1

Byte

Char

2

N/A

Date

8

Date

Decimal

16

Currency (8), Decimal (12)

Double

8

Double

Integer

4

Integer (2)

Long

8

Long (4)

Object

4

Variant

SByte

1

N/A

Short

2

N/A

Single

4

Single

String (variable size only)

Depends

String (supports fixed and variable size)

UInteger

4

N/A

ULong

8

N/A

UShort

2

N/A

User-Defined (Structure)

Depends

User-Defined (Type)


In both VB 6 and VB 2005, data types fall into one of two categories based on how they are stored and accessed:


Value types

A value type holds its data within its own memory allocation. You can access a value type directly without having to create a reference to it. Examples of value types are Integer and Single.


Reference types

A reference type contains a pointer to another memory location that holds the data. Examples of reference types are String and Object. We will discuss reference types in more detail in Chapter 3.

Variables in an application are stored in one of two different locations in memory: either on the stack or on the heap. Stacks are used for storing variables created in a function and are destroyed when the function exits. A heap, on the other hand, is used to store long-lived variables such as global and static variables.

Value types are stored directly on the stack at execution time, as opposed to being stored on the heap, as is done for reference types. You can access a value type directly without needing to create a reference to it. For a reference type, you must use a variable that contains a reference to the value of the type.



Visual Basic 2005 Jumpstart 2005
Visual Basic 2005 Jumpstart
ISBN: 059610071X
EAN: 2147483647
Year: 2005
Pages: 86
Authors: Wei-Meng Lee

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net