Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams 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!

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

edited to correct the error pointed by Ekkehard.Horner

@Ekkehard.Horner, of course, you are right. I should not post while being called for dinner. My fault. – MC ND Apr 4, 2017 at 20:40

As your specs boil down to a regular/computable mapping, Select Case or If .. ElseIf - i.e. cherry picking - are the wrong tools anyway:

Option Explicit
Dim i
For i = -1 to 42
    If 1 > i Or 40 < i Then
       WScript.Echo i, "invalid"
       WScript.Echo i, Chr(65 + ((i - 1) \ 10))
    End If

output:

cscript 43214055.vbs
-1 invalid
0 invalid
41 invalid
42 invalid

You're using VBScript in your page. It has no support of ranges in a Select Case statement. You may be better off using If/ElseIf statements.

If i > 0 And i <= 10 Then Response.Write("Grade A") ElseIf i > 10 And i <= 20 Then Response.Write("Grade B") ElseIf i > 20 And i <=30 Then Response.Write("Grade C") ElseIf i > 30 And i <= 40 Then Response.Write("Grade D") Response.Write("Invalid") End If