home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / ASP / elseif.asp < prev    next >
Encoding:
Text File  |  2001-06-08  |  3.1 KB  |  88 lines

  1. <%
  2. '*******************************************************
  3. '*     ASP 101 Sample Code - http://www.asp101.com     *
  4. '*                                                     *
  5. '*   This code is made available as a service to our   *
  6. '*      visitors and is provided strictly for the      *
  7. '*               purpose of illustration.              *
  8. '*                                                     *
  9. '* Please direct all inquiries to webmaster@asp101.com *
  10. '*******************************************************
  11. %>
  12.  
  13. <%
  14. ' Declare our variables... always good practice!
  15. Dim intExperience  ' A variable that will contain a #
  16.                    ' representing a unit of time of
  17.                    ' experience the user has doing
  18.                    ' something.
  19.  
  20. Dim strMessage     ' The message we output based on
  21.                    ' this hypothetical user doing
  22.                    ' something for a given amount of time.
  23.  
  24. ' Just so that I don't go crazy with all these vague
  25. ' somethings and units... lets say the number represents
  26. ' the number of months the user has been writing ASP code.
  27.  
  28. ' So now we need to go about getting our number somehow...
  29. ' since this part really has nothing to do with this sample,
  30. ' I'll just read in a # off the querystring and default it
  31. ' to 12 months (just so it's not a boring 0) if nothing is
  32. ' input.
  33.  
  34. ' Read in our value
  35. intExperience = Request.QueryString("months")
  36.  
  37. ' Check if we got a value
  38. If intExperience <> "" Then
  39.     ' If we did then we convert it to an integer.
  40.     ' This could cause a type mismatch, but I'm omitting
  41.     ' error checking for brevity.  (Too late... I know!)
  42.     intExperience = CInt(intExperience)
  43. Else
  44.     ' Otherwise default to our hypothetical 12
  45.     intExperience = 12
  46. End If
  47.  
  48. ' Now to the real sample code.
  49. ' It starts out like any other If Then, but notice there's
  50. ' no space between the Else and the next If.  If there were,
  51. ' this code would take on an entirely different meaning and
  52. ' actually wouldn't work!  It would instead give us a
  53. ' VBScript compilation error because we'd be missing the
  54. ' matching End If.
  55. If intExperience < 1 Then
  56.     strMessage = "newbie"
  57. ElseIf  1 <= intExperience And intExperience <  2 Then
  58.     strMessage = "novice"
  59. ElseIf  2 <= intExperience And intExperience <  6 Then
  60.     strMessage = "beginner"
  61. ElseIf  6 <= intExperience And intExperience < 12 Then
  62.     strMessage = "dangerous"
  63. ElseIf 12 <= intExperience And intExperience < 24 Then
  64.     strMessage = "intermediate"
  65. ElseIf 24 <= intExperience Then
  66.     strMessage = "advanced"
  67. End If
  68.  
  69. ' On a side note... I've always liked this type of syntax
  70. ' better, but it doesn't work like you'd expect it to in
  71. ' VBScript.   Worse yet, it doesn't throw an error either!
  72. ' It just always processes the If Then case.
  73. ' Can you figure out why?  ;)
  74. '
  75. 'Dim x
  76. 'x = 5
  77. 'If 3 < x < 7 Then
  78. '    Response.Write "X is between 3 and 7."
  79. 'End If
  80.  
  81. ' All that's left is for the script to do something with the
  82. ' value it calculated so I'll use it in a sentence below.
  83. %>
  84. <p>
  85. This script has determined that you are an ASP developer
  86. with a <%= strMessage %> level of experience.
  87. </p>
  88.