Chapter 6. Storing Information in Variables

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
Part II:  Visual Basic Programming Fundamentals


In this chapter

Declaring and Naming Variables

Understanding Data Types

Working with Numeric Data Types

Using Math Operations

Using Date and Time Values

Working with Strings

Using Arrays

Understanding Regional Settings

Exercise: Parsing Strings

In this chapter we will discuss variables. Variables are used to store information in the computer's memory while your programs are running. Three components define a variable:

  • The variable's name (which correlates to its location in memory)

  • The type of information being stored

  • The actual information itself

Suppose you are given this assignment: "Go count all the cars in the parking lot." As you count each car, you are storing information in a variable. Your location in memory is either a notepad or your brain. The type of information being stored is a number. And the actual information you are storing is the current number of cars.

As the name variable suggests, the information stored in a variable can change (vary) over time. In the example of counting cars, the count will be increased periodically. With any variable, there are two basic functions you can perform: storing information (writing on the notepad) and retrieving information (reading what is written on the notepad).

An assignment statement is used to store information in a variable, as in the following example:

 Dim LoneliestNumber As Integer  LoneliestNumber = 1 

In the example, the variable name is LoneliestNumber, the type of the variable is Integer, and the value being stored is the number 1.

Note

Many of the code samples in this chapter will be simple one- or two-line examples. To try any of these code samples, perform the following steps:

  1. Create a new Windows Application Project.

  2. Place a button on the form.

  3. Put the sample lines of code in the button's Click event.

  4. Use either the Debug.WriteLine function or the MessageBox.Show function to display the result.

You can use the same sample application for all the code samples in this chapter. The code for the major examples can be downloaded from the Web.



    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