0

I am a total novice with visual basic and teaching myself as I go along. I am building a VB in studio 2008 (I'm obliged to use this version) that logs into a device , transmits log in and password and then transmits commands read from a .txt file using reflections. All of this is working fine. The device executes the command and outputs 1 of 28 possible responses.

I am using select case to evaluate the responses and act accordingly. The device session stops as expected when EXECUTED is seen in the session window, my test data is designed so the first response I get is "EXECUTED", the weird thing is my VB "sees" the EXECUTED message (Case 1) but select case responds as if it has seen FAILED (Case 2), subsequent lines of the test data illicit different cases (5 and 6) but the response is always the next case along. I have tried Case n, case is = n, case "string value" but I get errors.

Here's my code - note that I haven't defined all 28 cases yet but the undefined ones are REM'ed out in my active version. Any ideas or suggestions would be gratefully received!

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
Dimbert
  • 11
  • 3

3 Answers3

0

You are missing a double quote " in your first Case. Try changing it to this:

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

Notice I've added the double quote before "Continue?".

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • Well spotted, my fat fingers I'm afraid! I had changed the message box from "Do you want to continue", to just "continue" to make it easier to read. Spotted when I debugged but unfortunately it didn't fix my problem :-( – Dimbert Feb 03 '15 at 13:50
0

Get rid of the With statement. Create and assign a holder variable and use that with the select statement. Doing so will allow you to see what is actually getting passed into the select statement by setting a stop point in the debugger.

Dim temp_resp as integer = refl.WaitForStrings(Dev_Resp, "0:4:30")
Select Case temp_resp
    'the case statements here.
End Select
  • Thanks Brandon. I tried this and popped in a msgbox and a breakpoint so I can have a look at the values. The host session sees the EXECUTED, and stops (ie reacts to it) as I hoped, but the value of temp_resp is 2 so it is reacting as if it has seen FAILED in the session window. My test data also illicits different case responses (5 and 6) but they step on to the next case too. – Dimbert Feb 04 '15 at 11:28
  • If the holder variable `temp_resp` has a value 2, then that is what is being returned by `refl.WaitForStrings(Dev_Resp, "0:4:30")`. The problem is not with the select statement but rather the `WaitForStrings` method of the refl object. – вʀaᴎᴅᴏƞ вєнᴎєƞ Feb 04 '15 at 15:47
  • Brandon sent me off in the right direction. Did some Googling and found this on the Attachmate site:- "WaitForStrings requires a zero-based array parameter, but it returns a 1-based index of strings. Use a Select Case statement with 1-based values to determine the host response." I use the messages stored in the array elsewhere, so I'm subtracting 1 from my .waitforstrings response so it lines up with the array, and means the code is still legible. – Dimbert Feb 05 '15 at 11:00
0

Reflections WaitForStrings uses a zero-based array parameter, but it returns a 1-based index of strings. Waitforstrings sees array entry zero as the first valid entry so the first select case (Case = 1) corresponds to array entry 0.

Dimbert
  • 11
  • 3