![]() |
|
|
| Lecture Three
This lecture will cover the topics of control structures (elementary selection and repetition), and of general procedures in Visual Basic. The menu to the right provides links to the major topics of the lecture as well as to the assignment page for this week. You may also scroll down to begin reading the lecture material.
|
Lecture Menu |
| Control Structures The three basic control structures are sequence, selection and repetition.
Selection
This causes the statement(s) in <true block> to be performed if <condition> is true; otherwise the statement(s) in <false block> are performed. This flow chart may help to visualize the situation.
Repetition
<loop body> Loop The above causes <condition> to be tested.
Thus a Do While loop may execute:
Conditions
in If-Then-Else and Do While control structures often make use of comparison
(or relational) operators, which are explained below.
Comparison
Operators in VB Common VB comparison operators (all of equal precedence): Operator -- Operation:
= -- equals The comparison
operators are lower in precedence than the arithmetic operators and
higher in precedence than the boolean operators (Not, And, Or, Xor,
Eqv and Imp, explained in Lecture IV).
Procedures are the primary structuring tool for programs.
To
illustrate a procedure call, consider the example below:
Sub example()
Private Sub
Form_Click() This flow chart may be of help in understanding the flow
of control during a procedure call and return. |
|
Arguments
Arguments are used by a procedure to communicate with the rest of the program. |
|
|
Save your program before running it.
|
|
| Quizzes
You will be tested on the Visual
Basic language and software Cint(Sqr(Abs(-10))) = 3. You will be expected to be able to predict the output
of short programs or code fragments, and to be able to write short programs
SAMPLE QUIZ 1. What will be printed on the form by the statement
below if the value of xray is: 2. For the following code answer the question below, assuming the form has been clicked. Private Sub Form_Click () What do Text1 and Text2 display following user input of (a) 45 (b) 69 (c) 68 to the input box? a) Text1__________ b) Text1___________ c) Text1____________ Text2____________ Text2____________
Text2____________ 3. What is displayed on the form, when clicked,
by the following? ANSWERS: 1. 2. b) Not so middle. c) Not so middle. 3. |
|