Tutorial 8 Slides

Tutorial 8
Introducing CheckBoxes &
Message Dialogs
Basic Structure of Simple Codes

Declare variables for input and output controls


Input



Read in assign input values to input variables
Use Val conversion function for numeric input data
Process


Use appropriate data types and prefixes
Using input and other elements, calculate the result.
Ouput

Assign the result into the output control.
Example
Error Handling
1.
2.
3.
4.
5.
Check error
Resolve error
Input
Process
Output
Code Structure with Error Handling
If [error condition] Then
do something, e.g. MessageBox
Else
input
process
output
End If
Or 
If [error condition] Then
do something, e.g. MessageBox
or Exit Sub
End If
input
process
output
Basic Structure
If [condition] Then
code(s) to be executed
End If
If intGrade >= 60 Then
lblCourseResult.Text = “Passed”
End If
Continue 
Coding with CheckBox



If chkMembership.Checked Then
or
If (chkMembership.Checked = True) Then
If (chkMembership.Checked = False) Then
Logical Operators
Logical
Operator
And
(AndAlso)
Or
(OrElse)
Not
Xor
Meaning
Example
Only if both conditions are true, then the
result is true.
If [condition1] And [condition 2]
If at least one condition is true, then the
result is true
If [condition1] Or [condition 2]
Negation of the condition. If the
condition is true, the result is false. If the
condition is false, then the result is true.
If Not [condition]
If one and only one of the conditions is
true, then the result is true. If all
conditions are either true or false, then the
result is false. So, if all conditions are
false, then the result is false. If all
conditions are true, then the result is also
false.
If blnStake Xor blnBurger Then
strCustomer = “Satisfied”
End If
If a customer is served with either a
stake or a burger, she is happy. But
if the customer is not served
anything or both, then she is not
happy. (too hungry or too full)
MessageBox Function

See textbook pages 174 and 175 for details