Link to home
Start Free TrialLog in
Avatar of ASPDEV
ASPDEV

asked on

Error 9 Subscript out of Range

Hi,

I get this error when I'm trying to read from COMM Port.

 Public Sub readme()

        Try

     
            Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
            Dim lngStatus As Long
            Dim strError As String = Nothing
            Dim strData As String = Nothing
           
            Dim lngSize As Long
            Dim LINE_BREAK As Short = 1
            Dim LINE_DTR As Short = 2
            Dim LINE_RTS As Short = 3
            Dim strRecieveData As String = Nothing

            'PortComm 'ActiveXObject("PortCommunication.PortComm")

            Dim objComport As New PortCommunication.PortComm

            ' Initialize Communications
            lngStatus = objComport.CommOpen(intPortID, "COM" & CStr(intPortID), _
                "baud=9600 parity=N data=8 stop=1")

            If lngStatus <> 0 Then
                ' Handle error.
                lngStatus = objComport.CommGetError(strError)
                MsgBox("COM Error: " & strError)// I get error here
            End If


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

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



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

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



            ' Close communications.
            Call objComport.CommClose(intPortID)

        Catch ex As Exception

        End Try
    End Sub

Thanks
Avatar of RunningGag
RunningGag

Does it give you a line number?  Subscription out of range generally means that you are trying to access a value outside of an array.
Avatar of ASPDEV

ASKER

No it doesn't give me any line number.
ASKER CERTIFIED SOLUTION
Avatar of chrisgreaves
chrisgreaves
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ASPDEV

ASKER

Thanks