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
ASPDEVAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RunningGagCommented:
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.
0
ASPDEVAuthor Commented:
No it doesn't give me any line number.
0
chrisgreavesCommented:
Should it not be:
strerror=objComport.CommGetError(lngStatus)
Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ASPDEVAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.