我试过以下内容:
Select Case Combo1.SelectedItem Or Combo2.SelectedItem
但我收到错误:
Conversion from String "string here" to type 'Long' is not valid
是否可以有多个选择案例?
答案 0 :(得分:29)
您可以使用逗号分隔多个值:
Case Combo1.SelectedItem, Combo2.SelectedItem
使用Or
会使它成为一个表达式,在与Select
中的值进行比较之前进行评估。
如果Select
中的值为Long
值,则可能需要转换控件中的字符串:
Case CLng(Combo1.SelectedItem), CLng(Combo2.SelectedItem)
要直接解决问题,不可能在select中使用多个值作为测试表达式:
Select Case v1, v2 'Not possible
答案 1 :(得分:1)
嗨Google搜索并没有回答就看到了这个问题。经过进一步的研究,我发现这可以用于我的目的。
基本上,你从:
开始选择案例为真
然后每个case语句可以是两个变量的组合。当两者都满足时,情况为真,并将执行适当的代码。
https://forums.asp.net/t/611892.aspx?To+do+a+select+case+using+two+variables+or+parameters
答案 2 :(得分:-2)
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