nvm got it
The problem is that it doesnt split them up correctly. The packets occasionally come in clumped.
Private Sub Process_Data(strData As String)
Dim intPacketSize As Integer, intPacketID As Integer
intPacketID = Asc(Mid(strData, 2, 1))
intPacketSize = Asc(Mid(strData, 3, 1))
ParseBNET(Mid(strData, 1, intPacketSize))
strData = Mid(strData, LenB(Mid(strData, 1, intPacketSize)))
If LenB(strData) > 4 Then
Process_Data (strData)
End If
End Sub
Don't delete your post like that, leave it so others can learn from your mistake
OK heres the new code that works.
Private Sub Process_Data(strData As String)
Dim intPacketSize As Integer, intPacketID As Integer
intPacketID = Asc(Mid(strData, 2, 1))
intPacketSize = Asc(Mid(strData, 3, 1))
ParseBNET(Mid(strData, 1, intPacketSize))
strData = Mid(strData, LenB(Mid(strData, 1, intPacketSize + 1)) / 2)
If LenB(strData) > 4 Then
Process_Data (strData)
End If
End Sub
This line needed to be changed.
strData = Mid(strData, LenB(Mid(strData, 1, intPacketSize + 1)) / 2)
You should use Len() because English is a single-byte character set language. LenB() is used for double-byte character set languages (Chinese, Japanese, Korean), hence if used with a single-byte character set language it returns the length * 2.
The function Len() is essentially just LenB() divided by two. Strings in Visual Basic are stored in Unicode, thus they take up 2 bytes each. Except, of coarse if you call strConv("String" ,vbFromUnicode) on them.
So the code "If Len(strData) > 2 Then" will do exactly the same as "If LenB(strData) > 4 Then" except the LenB() won will execute faster, but to no noticeable significance.