How To Solve This Error.......Subscript out of range (Error 9)

Shafique Ahmed 0 Reputation points
2023-02-08T21:42:31.2866667+00:00

Hi, Everyone

I am also Working on this modCOMM Code. I use this code to communicate with my weight scale. But can't figure out it which function or routine that i call on caommand button click Event.

----------------here is the code--------------

Option Compare Database

Private Sub Command157_Click()
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strError  As String
    Dim strData   As String


    ' Initialize Communications
    lngStatus = commopen(intPortID, "COM3" & CStr(intPortID), _
        "baud=9600 parity=N data=8 stop=1")
    If lngStatus <> 0 Then
    ' Handle error.
        lngStatus = CommGetError(strError)
    MsgBox "COM Error: " & strError
    End If
    

    ' Set modem control lines.
    lngStatus = CommSetLine(intPortID, LINE_RTS, True)
    lngStatus = CommSetLine(intPortID, LINE_DTR, True)

    ' Write data to serial port.
    lngSize = Len(strData)
    lngStatus = CommWrite(intPortID, strData)
    If lngStatus <> lngSize Then
    ' Handle error.
    End If



    ' Read maximum of 64 bytes from serial port.
    lngStatus = CommRead(intPortID, strData, 64)
    If lngStatus > 0 Then
        ' Process data.
    ElseIf lngStatus < 0 Then
        ' Handle error.
    End If

    ' Reset modem control lines.
    lngStatus = CommSetLine(intPortID, LINE_RTS, False)
    lngStatus = CommSetLine(intPortID, LINE_DTR, False)



    ' Close communications.
    Call CommClose(intPortID)
End Sub

Microsoft 365 and Office | Access | Development
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.