• Welcome to Valhalla Legends Archive.
 

Having trouble with Data Handler

Started by FrostWraith, August 02, 2006, 12:26 AM

Previous topic - Next topic

FrostWraith

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

Spilled

Don't delete your post like that, leave it so others can learn from your mistake

FrostWraith

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)

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.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

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.
~ FrOzeN