Understanding Data Types

function OpenWin(url, w, h) { if(!w) w = 400; if(!h) h = 300; window.open(url, "_new", "width=" + w + ",height=" + h + ",menubar=no,toobar=no,scrollbars=yes", true); } function Print() { window.focus(); if(window.print) { window.print(); window.setTimeout('window.close();',5000); } }
Team-Fly    

Special Edition Using Microsoft® Visual Basic® .NET
By Brian Siler, Jeff Spotts
Table of Contents
Chapter 6.  Storing Information in Variables


Okay, you know what a variable does and how to name it. But what can you store in a variable? The simple answer is: almost anything. A variable can hold a numeric value; a string of text; or a reference to an object, such as a form, control, or database. This chapter looks specifically at using variables to store numbers, strings, and dates. Table 6.2 lists Visual Basic's data types:

Table 6.2. Visual Basic Data Types

Visual Basic .NET Data Type

Values Stored

Example

Memory Requirements

Boolean

True/False

True

2 bytes

Byte

0 255

122

1 byte

Char

Single Character

A

2 bytes

Date

Dates and Times

12/21/1970 02:00 PM

8 bytes

Decimal

Decimal or Whole

19.95D

16 bytes

Double

Decimal Numbers

1.23E-10

8 bytes

Integer

Whole Numbers

8675309

4 bytes

Long

Whole Numbers

19-digit number

8 bytes

Object

A reference to an object of any type

 

4 bytes

Short

Whole Numbers

32,123

2 bytes

Single

Decimal Numbers

.0000123

4 bytes

String

Characters

HELLO

Depends on length

Note

The little Integer from VB 6.0 has finally grown up! A Visual Basic .NET Integer variable can store the entire range of values of a Visual Basic 6.0 Long variable. (This brings a welcome level of consistency to those programmers who work with the int type in SQL databases.) A new type, the Short type, takes the place of the VB6 Integer with a range of -32,768 to +32,767.


Note

The Currency data type from earlier versions of Visual Basic has been eliminated. The help files suggest using the new Decimal data type as a replacement.


Note

The Variant data type, capable of storing any other variable type, has been eliminated. Because all of the base data types derive from the Object class, Microsoft has named Object as the new universal data type.


In Visual Basic .NET, even the most basic data types act like objects, with their own properties and methods. When you type a variable name in the Code Editor and press the period key, you will see all the associated methods and properties.


    Team-Fly    
    Top
     



    Special Edition Using Visual Basic. NET
    Special Edition Using Visual Basic.NET
    ISBN: 078972572X
    EAN: 2147483647
    Year: 2001
    Pages: 198

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