Hi, Since I last posted this problem I have managed to narrow it down.
This program collects information from the RS232 and places it in a Textbox. Now each data string that is placed in the box has a start which is as follows:
-I-: Retrieving Flash Memory Settings
-I-: etc......
When this data has been received in on one textbox then I want the next data to go into another box. The following data looks like this:
-P-: -71.4 dBm
-P-: etc.................
I have managed to get the data running into two Textboxes but when I try to split the data looking at the string for the (I) or the (P) then I get a failure message. I am attaching the program ina running condition with the split code blanked out with ' .
I just hope someone can help, I have been trying to get this solved for a couple of weeks now.
PLEASE HELP or suggest how I could rewrite the program.
CODE
Option Explicit
Dim Newdata As String 'each imcoming packet is assembled here
Private Sub Form_Load()
Form1.Caption = "OE8PCK Digital Wattmeter"
With MSComm1
.CommPort = 4
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen = True
' Leave all other settings as default values.
End With
OutputDisplay.Text = "Infobox"
InformationDisplay.Text = "Databox"
Help.Text = "Helpbox"
Data.Text = "Databox"
Newdata = "" 'initialize to empty
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
Dim InBuff As String
Dim I As Integer 'used to inspect each incoming character
Dim theChar As String 'each received character
Dim theInfo As String
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement.
' This template is found in the Example
' section of the OnComm event Help topic
' in VB Help.
' Errors
Case comEventBreak ' A Break was received.
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
Case comEventFrame ' Framing Error.
Case comEventOverrun ' Data Lost.
Case comEventRxOver ' Receive buffer overflow.
Case comEventRxParity ' Parity Error.
Case comEventTxFull ' Transmit buffer full.
Case comEventDCB ' Unexpected error retrieving DCB]
' Events
Case comEvCD ' Change in the CD line.
Case comEvCTS ' Change in the CTS line.
Case comEvDSR ' Change in the DSR line.
Case comEvRing ' Change in the Ring Indicator.
Case comEvReceive ' Received RThreshold # of chars.
InBuff = MSComm1.Input 'received 1 or more characters
For I = 1 To Len(InBuff) 'examine each received character in sequence
theChar = Mid$(InBuff, I, 1) 'extract the next character
If Asc(theChar) = 13 Then 'Look for CR
theInfo = Mid$(Newdata, 2, 1) 'Loads the third letter in the String "Newdata" in "theInfo" is a (I) or (P)
'End If
'If Asc(theInfo) = 73 Then 'Look for (I)
InformationDisplay.SelStart = Len(InformationDisplay.Text)
InformationDisplay.SelText = Newdata + vbCr + vbLf 'include a CR and LF to separate from next line placed in OutputDisplay
'NewData = "" 'clear NewData so it can assemble the next packet
'theInfo = ""
'End If
'If Asc(theInfo) = 80 Then 'Look for (P)
OutputDisplay.SelStart = Len(OutputDisplay.Text)
OutputDisplay.SelText = Newdata + vbCr + vbLf 'include a CR and LF to separate from next line placed in OutputDisplay
'End If
Newdata = "" 'clear NewData so it can assemble the next packet
ElseIf Asc(theChar) = 10 Then 'received a linefeed - ignore it
Else
Newdata = Newdata + theChar 'received a character -- append it to NewData
'Print (NewData)
Data.SelStart = Len(Data.Text)
Data.SelText = Newdata + vbCr + vbLf
End If
Help.SelStart = Len(Help.Text)
Help.SelText = theInfo + vbCr + vbLf
'theInfo = ""
Next I
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
Case comEvEOF ' An EOF character was found in the
' input stream.
End Select
End Sub