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

问题描述

用vb重写在vba中完成的旧程序。我有一个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,"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),"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之后串联一个空格没有实际意义。只需将其添加到实际字符串中的for 之后即可。

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...