19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

462 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

3. Press F8 two more times. The Call statement is highlighted.<br />

4. Press F8 once <strong>and</strong> observe that the heading of the Sub procedure GetBalance is<br />

now highlighted in yellow.<br />

5. Press F8 three times to execute the assignment statements <strong>and</strong> to highlight the<br />

End Sub statement. (Notice that the Dim <strong>and</strong> Rem statements were skipped.)<br />

6. Press F8 <strong>and</strong> notice that the yellow highlight has moved back to the cmdButton_Click<br />

event procedure <strong>and</strong> is on the statement immediately following the<br />

Call statement.<br />

7. Click on the End icon to end the program.<br />

8. Repeat Steps 2 <strong>and</strong> 3, <strong>and</strong> then press Shift+F8 to step over the procedure Get-<br />

Balance. The procedure has been executed in its entirety.<br />

9. Click on the End icon to end the program.<br />

COMMUNICATION BETWEEN ARGUMENTS AND PARAMETERS<br />

The following walkthrough uses the Locals window to monitor the values of arguments <strong>and</strong><br />

parameters during the execution of a program.<br />

1. If you have not already done so, type the preceding program into the Code window.<br />

2. Press F8 <strong>and</strong> click on the comm<strong>and</strong> button.<br />

3. Select “Locals Window” from the View window. Notice that the variables from<br />

the cmdButton_Click event procedure appear in the Locals window.<br />

4. Press F8 three more times to highlight the Call statement. Notice that the value<br />

of the variable p has changed.<br />

5. Press F8 to call the Sub procedure. Notice that the variables displayed in the<br />

Locals window are now those of the procedure GetBalance.<br />

6. Press F8 three times to execute the procedure.<br />

7. Press F8 to return to cmdButton_Click event procedure. Notice that the value<br />

of the variable b has inherited the value of the variable bal.<br />

8. Click on the End icon to end the program.<br />

STEPPING THROUGH PROGRAMS CONTAINING SELECTION<br />

STRUCTURES: SECTION 4<br />

If Blocks<br />

The following walkthrough demonstrates how an If statement evaluates a condition to determine<br />

whether to take an action.<br />

1. Create a form with a comm<strong>and</strong> button (cmdButton) <strong>and</strong> a picture box (picBox).<br />

Set the AutoRedraw property of the picture box to True. Then open the Code<br />

window <strong>and</strong> enter the following procedure:<br />

Private Sub cmdButton_Click()<br />

Dim wage As Single<br />

picBox.Cls<br />

wage = Val(InputBox(“wage:”))<br />

If wage < 5.15 Then<br />

picBox.Print “Below minimum wage.”<br />

Else<br />

picBox.Print “Wage Ok.”<br />

End If<br />

End Sub

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!