0

我是一个具有视觉基础的新手,并且在我进行过程中自学。我正在 Studio 2008 中构建一个 VB(我必须使用这个版本),它登录到设备,传输登录名和密码,然后传输使用反射从 .txt 文件中读取的命令。所有这些工作正常。设备执行命令并输出 28 个可能响应中的 1 个。

我正在使用选择案例来评估响应并采取相应行动。当在会话窗口中看到 EXECUTED 时,设备会话按预期停止,我的测试数据经过设计,所以我得到的第一个响应是“EXECUTED”,奇怪的是我的 VB “看到”了 EXECUTED 消息(案例 1)但选择案例响应好像它已经看到 FAILED(案例 2),测试数据的后续行非法不同的案例(5 和 6)但响应始终是下一个案例。我试过 Case n, case is = n, case "string value" 但我得到了错误。

这是我的代码 - 请注意,我尚未定义所有 28 个案例,但未定义的案例在我的活动版本中已被移除。任何想法或建议将不胜感激!

Option Explicit On
Public Class modCaseSelect

Shared Sub Dev_Responses(ByVal refl) 

    Dim Result As String
    Dim CR = vbCr
    Dim Resp As Integer

    Dim Dev_Resp(28) As String

    Dev_Resp(0) = "RUNNING"
    Dev_Resp(1) = "EXECUTED"
    Dev_Resp(2) = "FAILED"
    Dev_Resp(3) = "SEMANTICS ERROR"
    Dev_Resp(4) = "NONEXISTENT"
    Dev_Resp(5) = "NOT FOUND"
    Dev_Resp(6) = "SPECIAL"
    Dev_Resp(7) = "CONFIRM: Y/N"
    Dev_Resp(8) = "CONFIRM (Y/N)"
    Dev_Resp(9) = "CONFIRM EXECUTION: Y/N"
    Dev_Resp(10) = "ALREADY EXECUTED"
    Dev_Resp(11) = ""
    Dev_Resp(12) = ""
    Dev_Resp(13) = ""
    Dev_Resp(14) = ""
    Dev_Resp(15) = ""
    Dev_Resp(16) = ""
    Dev_Resp(17) = ""
    Dev_Resp(18) = ""
    Dev_Resp(19) = ""
    Dev_Resp(20) = ""
    Dev_Resp(21) = ""
    Dev_Resp(23) = ""
    Dev_Resp(23) = ""
    Dev_Resp(24) = ""
    Dev_Resp(25) = ""
    Dev_Resp(26) = ""
    Dev_Resp(27) = ""
    Dev_Resp(28) = "IN PROGRESS"

    With refl

        Select Case .WaitForStrings(Dev_Resp, "0:4:30") 'checkDev_Resp

            Case 0 ' "RUNNING"
                Result = Dev_Resp(0)
                Resp = MsgBox((Dev_Resp(0) & CR & CR & Continue?"), 17, "Case 0 error")

            Case 1 ' "EXECUTED"
                Result = Dev_Resp(1)
                Resp = MsgBox((Dev_Resp(1) & CR & CR & "Continue?"), 17, "Case 1")

            Case 2 ' "FAILED"
                Result = Dev_Resp(2)
                Resp = MsgBox((Dev_Resp(2) & CR & CR & "Continue?"), 17, "Case 2 error")

            Case 3 ' "SEMANTICS ERROR"
                Result = Dev_Resp(3)
                Resp = MsgBox((Dev_Resp(3) & CR & CR & "Continue?"), 17, "Case 3 error")

            Case 4 ' "NONEXISTENT"
                Result = Dev_Resp(4)
                Resp = MsgBox((Dev_Resp(4) & CR & CR & "Continue?"), 17, "Case 4 error")

            Case 5 ' "NOT FOUND"
                Result = Dev_Resp(5)
                Resp = MsgBox((Dev_Resp(5) & CR & CR & "Continue?"), 17, "Case 5 error")

            Case 6 ' "SPECIAL"
                Result = Dev_Resp(6)
                Resp = MsgBox((Dev_Resp(6) & CR & CR & "Continue?"), 17, "Case 6 error")

            Case 7 ' "CONFIRM: Y/N"
                Result = Dev_Resp(7)
                .Transmit("Y" & CR)

            Case 8 ' "CONFIRM (Y/N)"
                Result = Dev_Resp(8)
                .Transmit("Y" & CR)

            Case 9 ' "CONFIRM EXECUTION: Y/N"
                Result = Dev_Resp(9)
                .Transmit("Y" & CR)

            Case 10 ' "ALREADY EXECUTED"
                Result = Dev_Resp(10)
                Resp = MsgBox((Dev_Resp(10) & CR & CR & "Continue?"), 17, "Case 10 error")

            Case 11 ' ""
                Result = Dev_Resp(11)

            Case 12 ' ""
                Result = Dev_Resp(12)

            Case 13 ' ""
                Result = Dev_Resp(13)

            Case 14 ' ""
                Result = Dev_Resp(14)

            Case 15 ' ""
                Result = Dev_Resp(15)

            Case 16 ' ""
                Result = Dev_Resp(16)

            Case 17 ' ""
                Result = Dev_Resp(17)

            Case 18 ' ""
                Result = Dev_Resp(18)

            Case 19 ' ""
                Result = Dev_Resp(19)

            Case 20 ' ""
                Result = Dev_Resp(20)

            Case 21 ' ""
                Result = Dev_Resp(21)

            Case 22 ' ""
                Result = Dev_Resp(22)

            Case 23 ' ""
                Result = Dev_Resp(23)

            Case 24 ' ""
                Result = Dev_Resp(24)

            Case 25 ' ""
                Result = Dev_Resp(25)

            Case 26 ' ""
                Result = Dev_Resp(26)

            Case 27 ' ""
                Result = Dev_Resp(27)

            Case 28 ' "IN PROGRESS"
                Result = Dev_Resp(28)
                Resp = MsgBox((Dev_Resp(28) & CR & CR & "Continue?"), 17, "Case 28 error")

            Case Else

        End Select
    End With
End Sub
End Class
4

3 回答 3

0

"在第一个Case. 尝试将其更改为:

Case 0 ' "RUNNING"
    Result = Dev_Resp(0)
    Resp = MsgBox((Dev_Resp(0) & CR & CR & "Continue?"), 17, "Case 0 error")

请注意,我之前添加了双引号"Continue?"

于 2015-02-03T12:57:33.233 回答
0

摆脱With声明。创建并分配一个持有者变量并将其与 select 语句一起使用。这样做将允许您通过在调试器中设置停止点来查看实际传递到 select 语句中的内容。

Dim temp_resp as integer = refl.WaitForStrings(Dev_Resp, "0:4:30")
Select Case temp_resp
    'the case statements here.
End Select
于 2015-02-03T16:30:59.017 回答
0

反射 WaitForStrings 使用从零开始的数组参数,但它返回从 1 开始的字符串索引。Waitforstrings 将数组条目 0 视为第一个有效条目,因此第一个选择案例 (Case = 1) 对应于数组条目 0。

于 2015-02-05T19:07:21.143 回答