CIS 115 Lecture05 VB-Variables
CIS 115 Lecture05 VB-Variables
Variable
should be declared first in the
procedure (style convention)
+= x += 2 x= x + 2 Add to
-= x -= 5 x= x 5 Subtract from
*= x *= 10 x= x * 10 Multiply by
/= x /= y x=x/y Divide by
\= x \= y x=x\y Int Divide by
&= x &= . x = x & . Concatenate
Operator precedence tells us the order in
which operations are performed
From highest to lowest precedence:
Exponentiation (^)
Multiplicative (* and /)
Integer Division (\)
Modulus (MOD)
Additive (+ and -)
Parentheses override the order of
precedence
Where precedence is the same,
operations occur from left to right
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 'iResultA is 35
iResultB = (intX + intY) * 5 'iResultB is 75
dResultA = intX - intY * 5 'dResultA is -15
dResultB = (intX - intY) * 5 'dResultB is 25
Redo the Calculate Gross Pay
example from Lecture 4 using
variables.
Redo the Calculator from HW2 using
variables.
Homework 3
Visual Basic - Variables
See handout for details and due date
Questions?