home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / ASP / case.asp < prev    next >
Encoding:
Text File  |  2001-06-08  |  2.1 KB  |  61 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 variable
  15. Dim iChoice
  16.  
  17. ' Read in the choice the user clicked on.
  18. ' This will equal "" (an empty string) if no choice is there
  19. iChoice = Request.QueryString("choice")
  20.  
  21. ' Execute the appropriate branch based upon the value of the variable we just read in.
  22. Select Case iChoice
  23.     Case "1"
  24.         %>
  25.         <H3>This is what happens when you click on Case 1</H3>
  26.         <%
  27.     Case "2"
  28.         %>
  29.         <H3>This is what happens when you click on Case 2</H3>
  30.         <%
  31.     Case "3"
  32.         %>
  33.         <H3>Surprise, Surprise, This is what you get when you click on Case 3</H3>
  34.         <%
  35.     Case Else
  36.         ' This executes if no of the other conditions are met!
  37.         ' This actually runs the first time through when the user
  38.         ' arrives at this page because the choice is blank.
  39. End Select
  40.  
  41. ' You might also notice that in the above cases I was comparing the value of iChoice
  42. ' to strings containing numbers and not to the actual numerical values 1, 2, and 3.
  43. ' If I wanted to use the numerical values I should technically convert iChoice to a
  44. ' number before doing the comparison because 3 is really not the same as "3".  VBScript
  45. ' will let you get away with it occasionally, but it's good practice to actually do the
  46. ' conversion and, as an additional benefit, doing so will also help avoid confusion
  47. ' when people are reading your code. CInt or CLng is the appropriate command:
  48. '
  49. 'Select Case CInt(iChoice)
  50. '    Case 1
  51. '        ...
  52. '    Case 2
  53. '        ...
  54. '    ...
  55. 'End Select
  56. %>
  57. Click on the different cases below:<BR>
  58. <A HREF="./case.asp?choice=1">Case 1</A> 
  59. <A HREF="./case.asp?choice=2">Case 2</A> 
  60. <A HREF="./case.asp?choice=3">Case 3</A>
  61.