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("PortCommun ication.Po rtComm")
Dim objComport As New PortCommunication.PortComm
' Initialize Communications
lngStatus = objComport.CommOpen(intPor tID, "COM" & CStr(intPortID), _
"baud=9600 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = objComport.CommGetError(st rError)
MsgBox("COM Error: " & strError)// I get error here
End If
' Set modem control lines.
lngStatus = objComport.CommSetLine(int PortID, LINE_RTS, True)
lngStatus = objComport.CommSetLine(int PortID, LINE_DTR, True)
' Write data to serial port.
lngSize = Len(strData)
lngStatus = objComport.CommWrite(intPo rtID, strData)
If lngStatus <> lngSize Then
' Handle error.
End If
' Read maximum of 64 bytes from serial port.
lngStatus = objComport.CommRead(intPor tID, strData, 64)
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
' Reset modem control lines.
lngStatus = objComport.CommSetLine(int PortID, LINE_RTS, False)
lngStatus = objComport.CommSetLine(int PortID, LINE_DTR, False)
' Close communications.
Call objComport.CommClose(intPo rtID)
Catch ex As Exception
End Try
End Sub
Thanks
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("PortCommun
Dim objComport As New PortCommunication.PortComm
' Initialize Communications
lngStatus = objComport.CommOpen(intPor
"baud=9600 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = objComport.CommGetError(st
MsgBox("COM Error: " & strError)// I get error here
End If
' Set modem control lines.
lngStatus = objComport.CommSetLine(int
lngStatus = objComport.CommSetLine(int
' Write data to serial port.
lngSize = Len(strData)
lngStatus = objComport.CommWrite(intPo
If lngStatus <> lngSize Then
' Handle error.
End If
' Read maximum of 64 bytes from serial port.
lngStatus = objComport.CommRead(intPor
If lngStatus > 0 Then
' Process data.
ElseIf lngStatus < 0 Then
' Handle error.
End If
' Reset modem control lines.
lngStatus = objComport.CommSetLine(int
lngStatus = objComport.CommSetLine(int
' Close communications.
Call objComport.CommClose(intPo
Catch ex As Exception
End Try
End Sub
Thanks
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.
ASKER
No it doesn't give me any line number.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks