Using Conditional Expressions
One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression is a part of a complete program statement that asks a True-or-False question about a property, a variable, or another piece of data in the program code. For example, the conditional expression
Price < 100
evaluates to True if the Price variable contains a value that is less than 100, and it evaluates to False if Price contains a value that is greater than or equal to 100.
You can use the following comparison operators in a conditional expression:
Comparison operator | Meaning |
= | Equal to |
<> | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
The following table shows some conditional expressions and their results. You'll work with conditional expressions in an exercise later in this chapter.
Conditional expression | Result |
10 <> 20 | True (10 is not equal to 20) |
Score < 20 | True if Score is less than 20; otherwise, False |
Score = Label1.Text | True if the Text property of the Label1 object contains the same value as the Score variable; otherwise, False |
TextBox1.Text = "Bill" | True if the word “Bill” is in the first text box; otherwise, False |