Computer memory locations where programmers can temporarily store data. The data may be entered by the user at the keyboard, or it may be read from a file, or it may be the result of a calculation made by the computer.
The memory locations are called variables because the contents of the locations can change as the application is running.
Every varialbe has a name, data type, scope, and lifetime.
See Figure 3.1 page 72
True, False
0 to 255
One Unicode character
A, B, C, ...
Thu, 01 Jan 1970 00:00:00 GMT
16 bytes
fixed-point number, no rounding
33.3333333
8 bytes
4 bytes
1,2,3,-10
8 bytes
1,2,3,-10
Default data type to a variable
-32,768 to 32,767
11.56, -12.99
"Hello, World"
See Figure 3.2
Start with a 3 character id
intScore, intRegionWest
m can be used to stand for module scope, mintScore
names must begin with a letter
names can not contain punctuation
names can contain numbers, but the number can not be at beginning, dec2002Sales
accessibility variablename [As datatype][= initialvalue]
Dim decPrice As Decimal
Private mblnDataOk As Boolena = True
Dim dblRate As Double dblRate = .5
Dim decPrice As Decimal decPrice = .03D]
shrAge = 35S intHours = 4I lngPopulation = 20500L decRate = .03D sngRate = .03F dblSales = 2356R charInitial = "A"C
Convert.ToDouble (value) Convert.ToInt16 (value) Convert.ToInt32 (value) Convert.ToSingle (value) Convert.ToString (value)
^ (exponentiation, 4^2 = 4 * 4 = 16)
- (negation)
*, / (multiplication & division)
\ (integer division)
Mod (modulus arithmetic)
+, -
intAge=intAge + 1
Where in the application's code the variable can be used
How long the variable remains in the computers internal memory.
Has procedure scope becuase only that procedure can use the variable. See Figure 3.10
Has module scope because it can be used by all of the procedures in the form. See Figure 3.11
Has block scope because it can be used by block of code If...THen...Else or For...Next
Const constantname [As datatype][= expression]
Const decPI As Decimal = 3.141593D
Const intMAX_HOURS As Integer = 40
Place an apostrophe (') before the text you want to treat as a comment.
By default Visual Basic .NET creates undeclared variables for you
Variables must be declared
Strings will not implicitly convert to numbers.
Numeric data types will be implicity converted to less restrictive types.
Implicit conversion to a more restrictive type will cause a syntax error.
Use short phrases to describe the steps a procedure needs to take to accomplish its goal
See Figure 3.19 page 90
Me.txtName.Text = "" Me.lblBonus.Text = Convert.ToString(decSales * .05D)
Me.txtname.Focus()
Expected Data - ???
Unexpected Data - ???
Locating errors in a program
Typing Errors
You enter instructions that don't give the expected results.
decAverage = decNum1 + decNum2 / 2
'Currency Format
Me.lblCommission.Text = decCommission.ToString("C")
'2 Decimal Didgets
Me.lblTotal.Text = decTotal.ToString("N2")
'Percent
Me.lblRate.Text = decRate.ToString("P")