CopyPublic Function Switch( _
ByVal ParamArray VarExpr() As Object _
) As Object
实例
Function matchLanguage(ByVal cityName As String) As String
Return CStr(Microsoft.VisualBasic.Switch( _
cityName = "London", "English", _
cityName = "Rome", "Italian", _
cityName = "Paris", "French"))
End Function
再看一个简单的实例
Module Module1
Sub Main()
Dim intValue As Integer = -10
Console.WriteLine("Absolute value: " & _
Microsoft.VisualBasic.Switch(intValue < 0, -1 * intValue, intValue >= 0, intValue))
End Sub
End Module
如果缩合switch case语法如下
Case后面需要的是值或值的范围。你现在Case后面的表达式求得的是True或False。
要么全用If,要么如下修改
VB.NET code
select case myrow1.Cells("积分").Value
case 0
...
case 60 to 79
...
case 80 to 99
...
case is > 100
...
case else
...
end select