sas

Topic: ASP


ASP Conditional Statements
  • If…Then…Else conditional statement
  • Select Case conditional statement

If…Then…Else conditional statement
If conditional expression is one of the most useful control structures which allows us to execute a expression if a condition is true and execute a different expression if it is False. If the condition is true the statements following the Then keyword will be executed, else the statements following the ElseIf will be checked and if true, will be executed, else the statements in the else part will be executed.

The following code demonstrates If..Then..Else conditional statement. It asks the user to enter a number between 1 and 3 in a textbox and checks for the number entered using the If..Then..Else statement and displays some text if the condition is true.

Private Sub IfThen_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles IfThen.Click
If CInt(TextBox1.Text) = 1 Then
Label1.Text = "You entered" & CInt(TextBox1.Text)
ElseIf CInt(TextBox1.Text) = 2 Then
Label1.Text = "You entered" & CInt(TextBox2.Text)
ElseIf CInt(TextBox1.Text) = 3 Then
Label1.Text = "You entered" & CInt(TextBox2.Text)
Else
Label1.Text = "You entered another number"
End If
End Sub

 

 

 

 

 

 

 




Prev