Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.

Similar presentations


Presentation on theme: "Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression."— Presentation transcript:

1 Conditional Expression 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.

2 Comparison Operators used in Conditional Expressions =Equal to <>Not equal to >Greater than <less than >=Greater than or equal to <=Less than or equal to

3 If... Then Decision Structures When a conditional expression is used in a special block of statements called a decision structure, it controls whether other statements in your program are executed and in what order they're executed. You can use an If...Then decision structure to evaluate a condition in the program and take a course of action based on the result. In its simplest form, an If... Then decision structure is written on a single line: If score >= 20 Then Label1.Text = "YOU win!"

4 If... Then Decision Structures In its simplest form, an If... Then decision structure is written on a single line: If score >= 20 Then Label1.Text = "YOU win!" Score >=20 is evaluated to determine whether the program should set the Text property of the Label1 object to “You win!" If the Score variable contains a value that's greater than or equal to 20, Visual Basic sets the Text property; otherwise, it skips the assignment statement and executes the next line in the event procedure. This sort of comparison always results in a True or False value. A conditional expression never results in maybe.

5 Boolean expressions Expressions that can be evaluated as True or False are also known as Boolean expressions, and the True or False result can be assigned to a Boolean variable or property. You can assign Boolean values to certain object properties or Boolean variables that have been created by using the Dim statement and the As Boolean keywords.

6 Logical Operators You can test more than one conditional expression in If.. Then and Elself clauses if you want to include more than one selection criterion in your decision structure. The extra conditions are linked together by using one or more of the logical operators: AndIf both conditional expressions are True, then the result is True. OrIf either conditional expression is True, then the result is True. NotIf the conditional expression is False, then the result is True. If the conditional expression is True, then the result is False. XorIf one and only one of the conditional expressions is True, then the result is True. If both are True or both are False, then the result is False. (Xor stands for exclusive Or.)

7 Select Case Decision Structure With Visual Basic, you can also control the execution of statements in your programs by using Select Case decision structures. A Select Case structure is similar to an If... Then... ElseIf structure, but it's more efficient when the branching depends on one key variable, or test case. You can also use Select Case structures to make your program code more readable.

8 Select Case Decision Structure The syntax for a Select Case structure looks like this: Select Case variable case value1 statements executed if value1 matches variable case value2 statements executed if value2 matches variable case value3 statements executed if value3 matches variable case Else statements executed if no match is found End Select


Download ppt "Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression."

Similar presentations


Ads by Google