Using ASP we often use the Case Select statement to choose an action dependant on a value.
e.g.
Select Case intPrice
Case 100
response.write(“Item Costs £100.00″)
Case 200
response.write(“Item Costs £200.00″)
Case 300
response.write(“Item Costs £300.00″)
Case Else
response.write(“Invalid Price”)
End Select
However, what happens if we want to choose an action when a value is between two other values?
If you’ve used VB then you’ll have used something like Case 0 To 100.
But, this doesn’t work in ASP.
There is, however, a workaround to this. In our example above we might want to show a message in one of 4 cases (with a value being stored in a variable called myValue):
- When the value is between £0 and £100;
- When the value is between £101 and £200;
- When the value is between £201 and £300;
- When the value is greater than £300;
We can do this using the following:
Select Case True
Case (myValue > 0 AND myValue <101)
response.write(“Item Cost Is Low”)
Case (myValue > 100 AND myValue <201)
response.write(“Item Cost Is Medium”)
Case (myValue > 200 AND myValue <301)
response.write(“Item Cost Is High”)
Case Else
response.write(“Invalid Item Cost”)
End Select
Here the Select Case True makes sure that we will consider all the possible Case statements and then the comparison within each statement dictates which will be TRUE.
I’m not sure if this is legitimate ASP or if it’s just a hack but it works!
Thanks. It works just perfect.