Programming Lecture #3 CS 101 Autumn 2006 Tariq Jadoon
In Lecture #2 Variables and Assignment statements New Controls –Label –CommandButton –Textbox
Variables & Assignment Statements A variable is a named storage space –Naming variables follows certain simple rules: [See page 19 Chapter 2 of Visual Basic Schaum’s outline] Assignment statements assign values to variables: Variable = Expression An assignment statement is NOT an equation
1 4 Variables & Assignment Statements X = 1 X = 4 Y = X XY 4
Processor Variables & Assignment Statements 4 X = 1 X = 4 Y = X X = Y + 2 XY =6 6
Today Swapping Variables Debugging Tools –Immediate Window –Single Stepping –Watch Conditional Statements
10 Swapping the Contents of Two Variables X = 10 Y = 20 XY 20
10 Swapping the Contents of Two Variables X = 10 Y = 20 X = Y XY 20
10 Swapping the Contents of Two Variables X = 10 Y = 20 Y = X XY 10 20
Swapping the Contents of Two Variables X = 10 Y = 20 Temp = Y Y = X X Y Temp 20 10
Swapping the Contents of Two Variables X = 10 Y = 20 Temp = Y Y = X X = Temp X Y 10 Temp 20
Debugging Using the Immediate Window as a scratchpad Placing Breakpoints Single stepping (F8) Placing Watches
Conditional Code VB has a number of block structures for conditional code: IF condition THEN action IF condition THEN action1 action2... END IF
Conditional Code (contd.) IF condition THEN action1 … ELSE action2 … END IF