Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select case for integers

Status
Not open for further replies.

nadskram

Programmer
May 21, 2001
41
US
cant select handle integer
ex
grade = 86
select case grade
case > 90
ltrGrade = "A"
case > 80
ltrGrade = "B"
case > 70
ltrGrade = "C"
case else
ltrGrade = "F"
end select

this doesnt work for me
 
That's not really your problem... It's the logic of your select case statement that is wrong. A select case is only good for one expression. Here is an excerpt form MSDN:

"A Select Case structure works with a single test expression that is evaluated once, at the top of the structure. The result of the expression is then compared with the values for each Case in the structure. If there is a match, the block of statements associated with that Case is executed" & "Notice that the Select Case structure evaluates an expression once at the top of the structure. In contrast, the If...Then...ElseIf structure can evaluate a different expression for each ElseIf statement. You can replace an If...Then...ElseIf structure with a Select Case structure only if each ElseIf statement evaluates the same expression."

So in other words, you need an if then else statement...

Later,
mwa
 
Not necessarally. I found a case not published by MS.
You cannot use ranges but you can use an expression you would like evaluated, like so:
Code:
Select Case True
   Case grade > 90
      'do some code
   Case grade > 80
      'do some code
   Case grade > 70
      'do some code
   Case Else
      'do some code
End Select

Basically when it enters the select statement it starts evaluating the first argument (True in this case) against each Case argument (in this case expressions). You can think of it as if it is doing an if statement for each argument supplied for a case:
Code:
If true=grade>90 then do the code following the case

It always uses an equals equivalency test between the two and it performs one for easch argument in the case statement.

The actual equivalency is actually a bit more complicated, but equivalence is a good enough example for this thread.

-Tarwn ________________________________________________________________________________
Sometimes it is how you ask the question: faq333-2924
Many ASP questions have already been answered, please check faq333-3048 and use the search tool before posting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top