Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: FrostWraith on August 02, 2006, 12:26 AM

Title: Having trouble with Data Handler
Post by: FrostWraith on August 02, 2006, 12:26 AM
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
Title: Re: Having trouble with Data Handler
Post by: Spilled on August 02, 2006, 01:30 AM
Don't delete your post like that, leave it so others can learn from your mistake
Title: Re: Having trouble with Data Handler
Post by: FrostWraith on August 02, 2006, 09:07 AM
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)
Title: Re: Having trouble with Data Handler
Post by: l2k-Shadow on August 03, 2006, 03:58 PM
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.
Title: Re: Having trouble with Data Handler
Post by: FrOzeN on August 04, 2006, 01:59 AM
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.