我尝试了以下:
Select Case Combo1.SelectedItem Or Combo2.SelectedItem
,但我得到了错误:
Conversion from String "string here" to type 'Long' is not valid
可以有多个选择的情况吗?
您使用逗号:
分离多个值Case Combo1.SelectedItem, Combo2.SelectedItem
使用Or
将其与Select
中的值相比,将其作为表达式。
如果您在Select
中的值是Long
值,则您可能需要从控件中转换字符串:
Case CLng(Combo1.SelectedItem), CLng(Combo2.SelectedItem)
直接解决这个问题,使用多个值作为选择中的测试表达式是不可能的:
Select Case v1, v2 'Not possible
嗨,谷歌搜索,看到这个问题没有答案。经过进一步的研究,我发现这是为了我的目的。
基本上,您从:
开始选择案例true
然后,每个案例语句可以是两个变量的组合。当两者满足时,情况是正确的,将执行适当的代码。
https://forums.asp.net/t/611892.aspx?to do select case case using two variables or parameters
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim value As Integer
For i = 1 To 3
For j = 1 To 5
value = (GetCode(i, j))
TextBox1.Text = TextBox1.Text & "i=" & i & "->j=" & j & "=" & value & vbCrLf
Next
Next
End Sub
Function GetCode(ByVal v1 As Integer, ByVal v2 As Integer) As Integer
Dim retval As Integer
Dim forselect As String
forselect = v1 & v2
Select Case forselect
Case 11
retval = 11
Case 12
retval = 12
Case 13
retval = 13
Case 14
retval = 14
Case 15
retval = 15
Case 21
retval = 21
Case 22
retval = 22
Case 23
retval = 23
Case 24
retval = 24
Case 25
retval = 25
Case 31
retval = 31
Case 32
retval = 32
Case 3, 3
retval = 33
Case 34
retval = 34
Case 35
retval = 35
End Select
Return retval
End Function