7.1 Conditional Operators
To control the VB program flow, we can use various conditional operators. Basically, they resemble mathematical operators. Conditional operators are very powerful tools, they let the VB program compare data values and then decide what action to take, whether to execute a program or terminate the program and more. These operators are shown in Table 7.1.
7.2 Logical Operators
In addition to conditional operators, there are a few logical operators which offer added power to the VB programs. There are shown in Table 7.2.
Table 7.1: Conditional Operators
| Table 7.2:Logical Operators
|
* You can also compare strings with the above operators. However, there are certain rules to follows: Upper case letters are less than lowercase letters, "A"<"B"<"C"<"D".......<"Z" and number are less than letters.
7.3 Using If.....Then.....Else Statements with OperatorsTo effectively control the VB program flow, we shall use If...Then...Else statement together with the conditional operators and logical operators.
* any If..Then..Else statement must end with End If. Sometime it is not necessary to use Else.
|
Example: Private Sub OK_Click() firstnum=Val(usernum1.Text) secondnum=Val(usernum2.Text) If total=firstnum+secondnum And Val(sum.Text)<>0 Then correct.Visible = True
End Sub |
*VBTutor lesson 7
No comments:
Post a Comment
Assalaamualaikum....
Ini web saya yang baru yang bisa di kasih coment yang ngawur.... alias terserah aja feh. he he