If..Then..Else..End If statement is one of conditional statements in Visual Basic 6 Programming. The statement format is as the following:
If Condition1 ThenStatement1 will be executed if Condition1 met (the condition1 result is true value), otherwise the Statement2 will be executed.
Statement1
Else
Statement2
End If
If Condition1 ThenIf Condition1 met, the Statement1 will be executed, if Condition2 met, the Statement2 will be executed, and so on.
Statement1
Else
If Condition2 Then
Statement2
Else
If Condition3 Then
Statement3
Else
Statement4
End If
End If
End If
Note: that Statement1, Statement2 and so on may be a single statement or a block of statements (one or more statements).
Example implementation on your program as follow:
In an examination if the student get mark more than or equal to 6 he/she pass the exam, however if his/her mark is less than 6 he/she fail.
So the program coding will be like this:
If Val(txtMark.Text) >= 6 ThenLook at below image for your illustration:
lblResult.Caption = "PASS"
Else
lblResult.Caption = "FAIL"
End If
In an examination the mark will be categorized as below conditions:
Mark = 10 is Excellent
Mark >= 9 and <10 is Very Good
Mark >= 8 and < 9 is Good
Mark < 8 is Poor
So the program coding will look like below list:
If Val(txtMark.Text) < 8 ThenLook at below image for your illustration:
lblCategory.Caption = "POOR"
Else
If Val(txtMark.Text) >= 8 And Val(txtMark.Text) < 9 Then
lblCategory.Caption = "GOOD"
Else
If Val(txtMark.Text) >= 9 And Val(txtMark.Text) < 10 Then
lblCategory.Caption = "VERY GOOD"
Else
lblCategory.Caption = "EXCELLENT"
End If
End If
End If
0 comments:
Post a Comment