将“if else”代码更改为“select case”

时间:2015-11-15 13:35:01

标签: vb.net

If (j = 0 or j = 1)
   S = "j equal 0 or j = 1"
Else
   if(j = 3)
      S = "j equals 3"
   Else
      If (j>4 and j<20)
      S = "j is greater than 4 and j<20"
      Else
          S = "Incorrect Value"
      End if
   End if
End if

1 个答案:

答案 0 :(得分:1)

试试这个:

    Select Case True
        Case j = 0 Or j = 1
            S = "j equal 0 or j = 1"
        Case j = 3
            S = "j equals 3"
        Case j > 4 And j < 20
            S = "j is greater than 4 and j<20"
        Case Else
            S = "Incorrect Value"
    End Select