Valhalla Legends Forums Archive | Visual Basic Programming | Having trouble with Data Handler

AuthorMessageTime
FrostWraith
nvm got it

The problem is that it doesnt split them up correctly. The packets occasionally come in clumped.
[code]
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
[/code]
August 2, 2006, 5:26 AM
Spilled[DW]
Don't delete your post like that, leave it so others can learn from your mistake
August 2, 2006, 6:30 AM
FrostWraith
OK heres the new code that works.

[code]
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
[/code]

This line needed to be changed.
[code]strData = Mid(strData, LenB(Mid(strData, 1, intPacketSize + 1)) / 2)[/code]
August 2, 2006, 2:07 PM
l2k-Shadow
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.
August 3, 2006, 8:58 PM
FrOzeN
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.
August 4, 2006, 6:59 AM

Search