13

我尝试了以下方法:

Select Case Combo1.SelectedItem Or Combo2.SelectedItem

但我得到了错误:

Conversion from String "string here" to type 'Long' is not valid

是否可以有多个选择案例?

4

3 回答 3

37

您可以使用逗号分隔多个值:

Case Combo1.SelectedItem, Combo2.SelectedItem

UsingOr将使它成为一个表达式,在与Select.

如果您的值Select是一个Long值,那么您可能需要转换控件中的字符串:

Case CLng(Combo1.SelectedItem), CLng(Combo2.SelectedItem)

要直接解决这个问题,在 select 中使用多个值作为测试表达式是不可能的:

Select Case v1, v2 'Not possible
于 2012-12-20T11:00:57.697 回答
1

嗨,谷歌搜索并看到这个问题没有答案。经过进一步研究,我发现这对我的目的有用。

基本上,你从以下开始:

选择案例真

那么每个case语句可以是两个变量的组合。当两者都满足时,情况为真,将执行适当的代码。

https://forums.asp.net/t/611892.aspx?To+do+a+select+case+using+two+variables+or+parameters

于 2017-03-01T16:35:22.330 回答
-3
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
于 2013-05-08T10:06:11.083 回答