ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
' Declare our variables... always good practice!
Dim intExperience  ' A variable that will contain a #
                   ' representing a unit of time of
                   ' experience the user has doing
                   ' something.
Dim strMessage     ' The message we output based on
                   ' this hypothetical user doing
                   ' something for a given amount of time.
' 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 # off the querystring and default it
' to 12 months (just so it's not a boring 0) if nothing is
' input.
' Read in our value
intExperience = Request.QueryString("months")
' Check if we got a value
If intExperience <> "" Then
	' If we did then we convert it to an integer.
	' This could cause a type mismatch, but I'm omitting
	' error checking for brevity.  (Too late... I know!)
	intExperience = CInt(intExperience)
Else
	' Otherwise default to our hypothetical 12
	intExperience = 12
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
' On a side note... I've always liked this type of syntax
' better, but it doesn't work like you'd expect it to in
' VBScript.   Worse yet, it doesn't throw an error either!
' It just always processes the If Then case.
' Can you figure out why?  ;)
'
'Dim x
'x = 5
'If 3 < x < 7 Then
'	Response.Write "X is between 3 and 7."
'End If
' All that's left is for the script to do something with the
' value it calculated so I'll use it in a sentence below.
%>
<p>
This script has determined that you are an ASP developer
with a <%= strMessage %> level of experience.
</p>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers