<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' 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. %>

This script has determined that you are an ASP developer with a <%= strMessage %> level of experience.