ASP 101 - Active Server Pages 101 elseif.aspx
<%@ Page Language="VB" %>
<script language="VB" runat="server">
	Sub Page_Load(sender As Object, e As EventArgs)
	End Sub
    Sub btnCalculate_Click(sender As Object, e As EventArgs)
		Dim intExperience As Integer
		Dim strMessage    As String
		' Just so that I don't go crazy with all these vague
		' somethings and units... lets say the number represents
		' the number of months the user has been writing ASP code.
		' So now we need to go about getting our number somehow...
		' since this part really has nothing to do with this sample,
		' I'll just read in a # from the form.
		' Read in our value
		If Not IsNumeric(txtMonthsDeveloping.Text) Then
			' Output appropriate error message or whatever.
			' Since this isn't the point of the sample I just
			' set it to some value.
			intExperience = 1
		Else
			intExperience = CInt(txtMonthsDeveloping.Text)
		End If
		' Now to the real sample code.
		' It starts out like any other If Then, but notice there's
		' no space between the Else and the next If.  If there were,
		' this code would take on an entirely different meaning and
		' actually wouldn't work!  It would instead give us a
		' VBScript compilation error because we'd be missing the
		' matching End If.
		If intExperience < 1 Then
			strMessage = "newbie"
		ElseIf  1 <= intExperience And intExperience <  2 Then
			strMessage = "novice"
		ElseIf  2 <= intExperience And intExperience <  6 Then
			strMessage = "beginner"
		ElseIf  6 <= intExperience And intExperience < 12 Then
			strMessage = "dangerous"
		ElseIf 12 <= intExperience And intExperience < 24 Then
			strMessage = "intermediate"
		ElseIf 24 <= intExperience Then
			strMessage = "advanced"
		End If
		' All that's left is for the script to do something with
		' the text selected (based on the user's input), so I'll
		' just use it in the sentence below.
		litExpLevel.Text = strMessage
    End Sub
</script>
<html>
<head>
<title>ASP.NET ElseIf Sample</title>
</head>
<body>
<form runat="server">
<p>
How long have you been writing ASP/ASP.NET code?
<asp:TextBox id="txtMonthsDeveloping" runat="server"
	size="2"
/>
months.
<asp:Button id="btnCalculate" runat="server"
	OnClick = "btnCalculate_Click"
	Text    = "Calculate Experience Level"
/>
</p>
<p>
This script has determined that you are an ASP developer with a
<asp:Literal id="litExpLevel" runat="server" />
level of experience.
</p>
</form>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/elseif_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>