30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

198 Procedures Chapter 6<br />

Setting Option Strict <strong>to</strong> On in the Property Pages applies the change globally,<br />

<strong>to</strong> the entire project. The programmer also can enable Option Strict within an individual<br />

code file by typing Option Strict On at the start of the file above any declarations<br />

or Imports statements.<br />

6.8 Value Types and Reference Types<br />

In the next section, we discuss passing arguments <strong>to</strong> procedures by value and by reference.<br />

To understand this, we first need <strong>to</strong> make a distinction between data types in <strong>Visual</strong> <strong>Basic</strong>.<br />

All <strong>Visual</strong> <strong>Basic</strong> data types can be categorized as either value types or reference types. A<br />

variable of a value type contains data of that type. Normally, value types are used for a single<br />

piece of data, such as an Integer or a Double value. By contrast, a variable of a<br />

reference type (sometimes called a reference) contains a location in memory where data is<br />

s<strong>to</strong>red. The location in memory can contain many individual pieces of data. Collectively,<br />

reference types are known as objects and are discussed in detail in Chapters 8, 9 and 10,<br />

Object-Based <strong>Program</strong>ming, Object-Oriented <strong>Program</strong>ming: Inheritance, and Object-Oriented<br />

<strong>Program</strong>ming: Polymorphism.<br />

Both value types and reference types include built-in types and types that the programmer<br />

can create. The built-in value types include the integral types (Byte, Short,<br />

Integer and Long), the floating-point types (Single and Double) and types<br />

Boolean, Date, Decimal and Char. The built-in reference types include Object and<br />

String (although type String often behaves more like a value type, as we discuss in<br />

the next section). The value types that can be constructed by the programmer include<br />

Structures and Enumerations. The reference types that can be created by the programmer<br />

include classes, interfaces and delegates. <strong>Program</strong>mer-defined types are discussed<br />

in greater detail in Chapter 8, Object-Based <strong>Program</strong>ming, Chapter 9, Object-<br />

Oriented <strong>Program</strong>ming: Inheritance and Chapter 15, Strings, Characters and Regular<br />

Expressions.<br />

The table in Fig. 6.10 lists the primitive data types, which form the building blocks for<br />

more complicated types, such as classes. If Option Explicit is set <strong>to</strong> On, all variables<br />

must have a type before they can be used in a program. This requirement is referred <strong>to</strong> as<br />

strong typing.<br />

Type<br />

Size<br />

in bits Values Standard<br />

Boolean 16 True or False<br />

Char 16 One Unicode character (Unicode character set)<br />

Byte 8 0 <strong>to</strong> 255<br />

Date 64 1 January 0001 <strong>to</strong> 31 December 9999<br />

0:00:00 <strong>to</strong> 23:59:59<br />

Decimal 128 1.0E-28 <strong>to</strong> 7.9E+28<br />

Short 16 –32,768 <strong>to</strong> 32,767<br />

Fig. Fig. 6.10 6.10 <strong>Visual</strong> <strong>Basic</strong> primitive data types (part 1 of 2).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!