从字符串类型长错误信息框转换

Conversion from string type long error message box

重写在 vba 中完成的旧程序 vb。我有一个 for 循环,用于检查以确保下拉选择与其他 ddl 选择不匹配。我在两条 MessageBox.Show 行上收到“从字符串到类型 'Long' 的转换无效”,我尝试将 And 和 & 全部移动,但仍然出现错误。注释掉的部分是我在 vba 中的内容。语法应该如何?

 Dim TCi(0 To 3) As String
        TCi(1) = "Air Temperature"
        TCi(2) = "Out Temperature(A)"
        TCi(3) = "Inlet"

        Dim TCj(0 To 3) As String
        TCj(1) = "Air Temperature"
        TCj(2) = "Out Temperature(A)"
        TCj(3) = "Inlet"

        SelectionFlagA = 0
        SelectionFlagB = 0
        TCSflag = 0
        For i = 1 To 3
            TCChannel = Me.Controls.Item("TCSDropDown" & i).Text
            If TCChannel = "Channel_Not_Available" Then
            ElseIf TCChannel = "Select Temp" Then
                TCSflag = TCSflag + 1
                'This code works
                MessageBox.Show("You selected the same temp for both" & TCi(i) & " and " & TCj(j), "Conflicting Temp Selection!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit For
            Else
                If InStr(1, TCChannel, "A") Then
                    SelectionFlagA = 1
                End If
                If InStr(1, TCChannel, "B") Then
                    SelectionFlagB = 1
                End If

                For j = 1 To 3

                    If TCi(i) <> TCj(j) Then
                        TCChannel1 = Me.Controls.Item("TCSDropDown" & j).Text
                        If TCChannel1 = "Channel_Not_Available" Then
                        Else
                            If TCChannel = TCChannel1 Then
                                'This code works
                                MessageBox.Show("You selected the same temp for both " & TCi(i) And "" & TCj(j), vbCritical, "Conflicting Temp Selection!")
                                'VBA Line: MsgBox "You selected the same temp for both " & TCi(i) & " and " & TCj(j), vbCritical, "Conflicting Temp Selection!"
                                TCSflag = TCSflag + 1
                                Exit For
                            End If
                        End If
                    End If
                Next
                If TCSflag >= 1 Then
                    Exit For
                End If
            End If


        Next

您应该能够准确使用 VBA 代码中的内容

MessageBox.Show("Please select a temp for" & " " & TCi(i), "Error")

也就是说,在 ... a temp for 之后连接 space 没有实际意义。只需在实际字符串中的 for 之后添加即可。

MessageBox.Show("Please select a temp for " & TCi(i), "Error")