Results 1 to 6 of 6

Thread: [RESOLVED] Very wierd problem..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Resolved [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:
    1. Private Sub TCPDriver_RecievedPacket(IPHeader As clsIPHeader, TCPProtocol As clsTCPProtocol, Data As String)
    2. Debug.Print Data
    3. Debug.Print "-------------"
    4. If InStr(1, Data, "÷") <> 0 Then
    5.         MsgBox Len(Data)
    6.         MsgBox Data
    7.         MsgBox Mid(Data, 1, Len(Data))
    8. 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?

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    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?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Very wierd problem..

    Quote 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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    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
  •  



Click Here to Expand Forum to Full Width