|
-
Apr 14th, 2006, 08:25 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Very wierd problem..
I've editted a packetsniffer which i downloaded from planet-source-code.
Basically I'm trying to parse the data coming into the computer
I've used this as the code;
VB Code:
Private Sub TCPDriver_RecievedPacket(IPHeader As clsIPHeader, TCPProtocol As clsTCPProtocol, Data As String)
Debug.Print Data
Debug.Print "-------------"
If InStr(1, Data, "÷") <> 0 Then
MsgBox Len(Data)
MsgBox Data
MsgBox Mid(Data, 1, Len(Data))
End If
The sub and modules themselves are not the problem, as I've used them before, but never had this problem.
Basically, Debug.print is printing out all the data incoming to the computer, and this works 100% fine.
When the If statement is triggered, the first messagebox gives a length of approx 40 something, but when the second messagebox appears, its value is only a few characters long
A sample of what 'Data' could be is
÷1 à dakkonblade àÜÿjô
If I were to msgbox data, it would return
÷1
The causes a problem, because when I use Instr(1,Data,"à"), it will always return 0.
I really have no idea what could be causing this, as debug.print returns the right value, Len(Data) returns the right value, but msgbox or validation checks are always cut off.
Does anyone have an Idea of what's happening here?
-
Apr 14th, 2006, 08:30 AM
#2
Re: Very wierd problem..
That might be a Chr(0) or a string/line end character. You might need to transfer to a byte array, replace those charcters with spaces or "", then rebuild the string from the byte array
-
Apr 14th, 2006, 08:38 AM
#3
Re: Very wierd problem..
The VB MsgBox function is a wrapper around the MessageBox api, which works with null terminated strings. If there is a null character [chr(0)] in the string, the messagebox won't show anything past that. This is only a problem of the messagebox, and has no influence on any InStr results.
I think your problem is that the debug window, and also a messagebox will show non-printable characters like , but because all unprintable characters are displayed like doesn't mean that they are equal to each other.
so if the data contains the following sequence of characters:
à (asc 224)
(asc 4)
(asc 5)
It may look like à , but it is not the same as
à (asc 224)
(asc 23)
(asc 6)
So the InStr returns 0
EDIT: corrected an error
PS: The values 224, 23 and 6 come from your post. I copied and pasted them.
Last edited by Frans C; Apr 14th, 2006 at 08:44 AM.
Frans
-
Apr 14th, 2006, 08:38 AM
#4
Thread Starter
Hyperactive Member
Re: Very wierd problem..
I've checked that with the ---------- seperaters, they're all on one line in the Debug panel.
Also, if data = Test1 & vbcrlf & Test2, wouldn't Instr(1,Data,Test2) would still return > 0?
-
Apr 14th, 2006, 08:42 AM
#5
Thread Starter
Hyperactive Member
Re: Very wierd problem..
 Originally Posted by Frans C
à (asc 224)
(asc 4)
(asc 5)
It may look like à , but it is not the same as
à (asc 224)
(asc 23)
(asc 23)
So the InStr returns 0
Yep, I thought of that too.
I copied the data printed in the debug window to a new VB program, and ran the check again there, and it worked, the blocks are the same ascii.
I have no idea why this is happening, as I've written the exact same code previously, and it worked fine. Re-imaged without backing it up, and i have to write it again :s
-
Apr 14th, 2006, 09:06 AM
#6
Thread Starter
Hyperactive Member
Re: [RESOLVED] Very wierd problem..
Apparantly the null characters (chr(0)) do stop Instr(), I replaced them and all's well. Thanks guys
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|