VB SCRIPT CONDITIONAL STATEMENT
Conditional statement are used to perform different action for different decision .
- If statement
- If..Then ... Else statement
- If ....Then .... Else If statement
- Select statement
If ...Then..Else :
- Execute some code if a condition is true
- Select one of two blocks of code to execute.
Ex:
<script>
Funtion greeting ()
i=hour(time)
If I<10 Then
document.write("good morning")
Else
document.write("have a nice day")
End If
End Funtion
</script>
If...Then...ElseIf :
You can use the If..Then...ElseIf statement if you want to select one of many blocks of code to execute .
Ex:
<script>
Funtion greeting()
I=hour(time)
If I=10 Then
document.write("just started ")
ElseIf I=11 then
document.write("hungry")
ElseIf I=12 then
document.write("ah lunch time ")
Else
document.write("unknown")
End IF
End Funtion
</script>
Select statement :
You can also the "Select Case " stay if you want to select one of many blocks of code to execute .
Ex:
<script>
d=weekday(date)
Select Case d
Case 1
document.write("Sunday")
Case 2
document.write("moday")
Case 3
document.write("tuesday")
Case 4
document.write("Wednesday")
Case 5
document.write("Thursday")
Case 6
document.write("friday")
Case else
document.write("saturday")
End Select
</script>
0 Comments