• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 956
  • Last Modified:

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
0
ASPDEV
Asked:
ASPDEV
  • 2
1 Solution
 
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
 
ASPDEVAuthor Commented:
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now