<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
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
intExperience = CInt(txtMonthsDeveloping.Text)
' 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"
' 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
<title>ASP.NET ElseIf Sample</title>
How long have you been writing ASP/ASP.NET code?
<asp:TextBox id="txtMonthsDeveloping" runat="server"
<asp:Button id="btnCalculate" runat="server"
OnClick = "btnCalculate_Click"
Text = "Calculate Experience Level"
This script has determined that you are an ASP developer with a
<asp:Literal id="litExpLevel" runat="server" />
level of experience.
Click <a href="http://www.asp101.com/samples/elseif_aspx.asp">here</a>
to read about and download the source code.