Using Conditional Expressions


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



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net