| Chapter 3- Data Types and Operators | Boolean Expressions Page 2 3 4 |
| The If Statement Page 2 3 4 5 6 7 8 9 | |
| Arithmetic Operations Page 2 3 4 5 6 | Boolean Operators and Nested If Statements Page 2 3 4 5 6 7 |
| Events and Sequential Processing Page 2 3 4 5 | More Examples Page 2 3 4 5 6 7 8 9 10 11 12 |
| Datatypes and Conversions Page 2 3 4 5 6 7 | Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10 |
| Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Exercises Page 2 3 4 5 6 7 8 |
| Chapter 4- Selection Statements | Review Questions |
| Introduction | |
4-2: Boolean Expressions
The code for the complete program is shown here:
Private Sub btnCheck_Click( ... ) ...
'
' Experiment by changing the data types of variables
valueOne
' and(valueTwo)
'
Dim valueOne, valueTwo As Double
Dim
compare As Boolean
'
' Assign values from the textboxes (converted
appropriately)
' to the two variables.
'
valueOne =
Convert.ToDouble(txtValue1.Text)
valueTwo =
Convert.ToDouble(txtValue2.Text)
'
' Compare valueOne and valueTwo and
assign result to variable
' compare.
' Experiment by changing the
comparison operator
'
compare = (valueOne = valueTwo)
'
' Display
the result of the comparison (i.e. the value of
' variable compare) in the
text of the label object.
'
lblAnswer.Text = compare
End Sub
The code shows variables valueOne and valueTwo declared as Double and the comparison operator as =, but we should change these as we explore the comparison of values. Table 4-2 suggests a set of experiments you should perform. Predict the "answer" before running the program!
Table 4-2: Experimenting with Comparison Operators.
| varOne data type |
value1 | varTwo data type |
value2 | Comparison Operator | Result |
|---|---|---|---|---|---|
| Double | 3.2 | Double | 3.3 | = | ? |
| Double | 3.2 | Double | 3.2 | = | ? |
| Double | 3.2 | Double | 0.32e1 | = | ? |
| Double | 3.2 | Double | 3.3 | < | ? |
| Double | 3.2 | Double | 3.2 | < | ? |
| Double | 3.2 | Double | 0.32e1 | < | ? |
| Double | 3.2 | Integer | 3 | = | ? |
| Double | 3.2 | Integer | 3 | < | ? |
| Double | 1.25634735 | Single | 1.2563473 | = | ? |
| String | 3.2 | Integer | 3 | = | ? |
| String | 3.2 | Double | 3.2 | = | ? |
| String | 0.32e1 | Double | 3.2 | = | ? |
| String | 0.32e1 | String | 3.2 | = | ? |
| String | John | String | john | = | ? |