Select Case With Conditions ( Classic ASP)

Skullcandy picture Skullcandy · Apr 4, 2017 · Viewed 18.4k times · Source
<%
i=2 
  Select Case i
  Case 1,2,3,4,5,7,8,9,10
    response.write("Grade A")
  Case 11,12,13,14,15,16,17,18,19,20  
    response.write("Grade B")
  Case 21,22,23,24,25,26,27,28,29,30
    response.write("Grade C")
  Case 31,32,33,34,35,36,37,38,39,40
    response.write("Grade D")
  Case Else
    response.write("Invalid")
  End Select
  %> 

how to replace 1,2,3.. with a smaller statement. I have tried putting 1 To 10 but it is showing error.

Appreciate any help , thank you!

Answer

MC ND picture MC ND · Apr 4, 2017

Some alternatives

grade = "Invalid"
Select Case True
    Case i < 1   
    Case i < 11 : grade = "Grade A"
    Case i < 21 : grade = "Grade B"
    Case i < 31 : grade = "Grade C"
    Case i < 41 : grade = "Grade D"
End Select 

or

If i > 0 And i < 41 Then 
    grade = "Grade " + Chr(Asc("A") + (i-1)\10)
Else 
    grade = "Invalid"
End If 

or

If i > 0 And i < 41 Then 
    grade = Array("Grade A", "Grade B", "Grade C", "Grade D")((i-1)\10)
Else 
    grade = "Invalid"
End If 

edited to correct the error pointed by Ekkehard.Horner