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

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
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)
	' 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.
This script has determined that you are an ASP developer
with a <%= strMessage %> level of experience.

Back the the Sample Output

Back to the Sample Index

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



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