If/ElseIf statements can also be written using the Select Case statement. Most popular programming languages have an equivalent to a Select Case statement. The Switch statement is the equivalent statement in many languages. VBA-Excel, Access, Java, C#, C++, and Javascript, for example, all have a switch statement.
Parameters or Arguments
test_expression
  A string or numeric value. It is the value that you are comparing to the list of conditions. (ie: condition_1, condition_2, ... condition_n)
condition_1, ... condition_n
  Conditions that are evaluated in the order listed. Once a condition is found to be true, it will execute the corresponding code and not evaluate the conditions any further.
result_1, ... result_n
The code that is executed once a condition is found to be true.
Select Case Format
Select Case [variable]
Case [condition 1]
[Statement 1]
Case [condition 2]
[Statement 2]
Case [condition n]
[Statement n]
Case Else
[Statement else]
End Select
Example
Code
sub selectcaseoption()
dim i as integer
i=inputbox("Please input Number")
select case i
    case 1:
      Msgbox("Discount 5 dollar for you")
    case 2:
      Msgbox("Discount 10 dollar for you")
    case 3:
      Msgbox("Discount 15 dollar for you")
    case 4:
      Msgbox("Discount 15 dollar for you")
    case Else:
      Msgbox("No Discount for you")
End Select
End sub
Please Watching My Vidoe is Below
No comments:
Post a Comment