Select Case expression
Case value1
Script part if value1 matches
Case value2
Script part if value2 matches
End Select
Here is the code part in a simple example where a number is stored in a variable and then it is matched with different Cases inside a Select Case statement.
Dim my_num
my_num=150
Select Case my_num
Case 100
Response.Write "It is equal to 100" & "<br>"
Case 150
Response.Write "It is equal to 150" & "<br>"
Case 200
Response.Write "It is equal to 200" & "<br>"
End Select
The output of the above line is 'It is equal to 150'
Case 150, 160
Response.Write " It is equal to 150 or 160 " & "<br>"
If none of the value matches with the variable we have set then we can keep one default value for this by using Case Else. So in the code below the Case Else statement will be executed.
Dim my_num
my_num=160
Select Case my_num
Case 100
Response.Write "It is equal to 100" & "<br>"
Case 150
Response.Write "It is equal to 150" & "<br>"
Case Else
Response.Write "It is not equal to any listed value" & "<br>"
End Select
Here the Case Else part will be executed as all other cases will fail to match.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.