Case Structure
 

 



The case structure is another way of expressing a nested If statement.








If [condition 1] Then


      [instruction 1]


ElseIf [(condition 2] Then


        [instruction 2]


ElseIf [condition 3] Then


          [instruction 3]


Else


      [instruction 4]


End If


Select Case [one variable]


Case [value 1]


          [instruction 1]


Case [value 2]


          [instruction 2]


Case [value 3]


          [instruction 3]


Case [value 4]


          [instruction 4]


End Select



Among all cases, only the first matching condition and its instruction is executed and the rest of the Case statement is terminated.


Sample:







Select Case intAge

Case 16

Label1.Caption = “You can drive now!”

Case 18

Label1.Caption = “You can vote now!”

Case 21

Label1.Caption = “You can drink wine!”

Case 65

Label1.Caption = “Time to retire and have fun!”

End Select

(c) Shilpa Sayura Foundation 2006-2017