Académique Documents
Professionnel Documents
Culture Documents
names
Every variable has three properties:
Name - reference to the location - cannot be changed
Value - the information that is stored - can be changed
a control property
Hold data/information so that it can be
recalled for use at a later point in the code
Data type
Prefix Size
Values
Byte
Short
Integer
Long
byt
shr
int
lng
1 byte
2 byte
4 byte
8 byte
Single
Double
Decimal
sng
dbl
dec
Char
Boolean
chr
bln
String
Date
Object
str
dtm
obj
Example:
Data type
Zero (0)
False
Binary 0
Empty
12:00 a.m. on January 1, 0001
Actual value/data/information
Similar to a variable, but can NOT change
during the execution of a program.
Examples of Literals:
Numeric: 5 ; 157 ; 195.38256
String: Paul ; Hello!!! ; Jackson, AL 36545
Char: a ; 1 ; ? ; @
Boolean: True ; False
always obvious
If sales tax rate changes, must find and change every
occurrence of .06 or 1.06
Variables that share the same scope cannot have the same
When the code block ends the local variables are destroyed
Memory is given back to the operating system
intNumber1 = 4
intNumber2 = 3 * (2 + 2)
intNumber3 = intNumber1
IntNumber1 = intNumber1 + 6
intCount becomes 12
Double to Single
Single to Integer
Long to Integer
Val Function
Val("34.90)
Val("86abc)
Val("$24.95)
Val("3,789)
Val(")
Val("x29)
Val("47%)
Val("Geraldine)
Value Returned
34.9
86
0
3
0
0
47
0
lblNumber control
Arithmetic Operators
^
*
/
\
MOD
+
&
Exponential
Multiplication
Floating Point Division
Integer Division
Modulus (remainder from division)
Addition
Subtraction
String Concatenation (putting them together)
Examples of use:
decTotal = decPrice + decTax
decNetPrice = decPrice - decDiscount
dblArea = dblLength * dblWidth
result
shrHundreds = 157 \ 100
result
shrTens = (157 - 157 \ 100 * 100)
result
is 3
is 1
\ 10
is ?
result is 2
result is 2.5
Bob
Bob Smith
intX = 1
intY = 2
intResult = intX + intY
strOutput = intX & + & intY & = & intResult
1 + 2 = 3
Usage
x += 2
x -= 5
x *= 10
x /= y
x \= y
x &= .
Equivalent to
x=x+2
x=x5
x = x * 10
x=x/y
x=x\y
x = x & .
Effect
Add to
Subtract from
Multiply by
Divide by
Int Divide by
Concatenate
Exponentiation (^)
Multiplicative (* and /)
Integer Division (\)
Modulus (MOD)
Additive (+ and -)
Parenthesis
Exponential
Multiplication / Division
Integer Division
MOD
Addition / Subtraction
String Concatenation
Relational Operators (< , > , >= , <= , <>)
Logical Operators (AND, OR, NOT)
6 * 2 ^ 3 + 4 / 2 = 50
7*4/26=8
5 * (4 + 3) 15 Mod 2 = 34
intX = 10
intY = 5
intResultA = intX + intY * 5
iResultB = (intX + intY) * 5
dResultA = intX - intY * 5
dResultB = (intX - intY) * 5
'iResultA is 35
'iResultB is 75
'dResultA is -15
'dResultB is 25
Homework 3
Visual Basic - Variables
See handout for details and due date
Questions?