Hi All

Could one of you experts have a look at the code below I have a problem where I send data though com1 which is 13 chars long and get sent to textbox1 and if the data sent is less than 13 or more than 13, when i send the next data which is 13 chars long for some reason it contains the last char of the data from the data before in front of the new data what i would like for it to reject anything thats less than 13 or more than 13 maybe bring a msg up if it is. sample 12345678901234 is sent but is 14 chars long then after i send 13 chars in the textbox becomes 4123456789012

Option Explicit

Private strRX As String

Private Sub Form_Load()
' Fire Rx Event Every Two Bytes
MSComm1.RThreshold = 1

' When Inputting Data, Input 2 Bytes at a time
MSComm1.InputLen = 13

' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "9600,N,8,1"
' Disable DTR
MSComm1.DTREnable = False

' Open COM1
MSComm1.CommPort = 1 ' Set Com Port to 1
MSComm1.PortOpen = True ' Turn on Com Port
MSComm1.InBufferCount = 0 ' Clear Buffers
End Sub

Private Sub MSComm1_OnComm()
'
' Assumes RTHreshold Property is set to a value > 0
' (Recommended value is 1)
'
Static strBuffer As String
Dim strData As String
'Dim strRX As String
Dim boComplete As Boolean
Select Case MSComm1.CommEvent
Case comEvReceive
strData = MSComm1.Input
strBuffer = strBuffer & strData
Do
If Len(strBuffer) >= 13 Then
strRX = Mid$(strBuffer, 1, 13)

Text1.Text = strRX
MSComm1.InputLen = 0
'
' rest of your code goes here - strRX contains the 13 characters sent
' After you've done all your processing add the following code
'
If Len(strBuffer) = 13 Then
strBuffer = ""
boComplete = True
Else
strBuffer = Mid$(strBuffer, 14)
End If
Else
boComplete = True
End If
Loop Until boComplete = True
End Select
End Sub

Regards
Steve