Results 1 to 6 of 6

Thread: [RESOLVED] Cannot use "Byval" string to connect with strings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Resolved [RESOLVED] Cannot use "Byval" string to connect with strings

    Hello everyone!
    I'm working on a class that creates a communication between multiple
    computers. When a client connects he has an ID which is a string.
    Now I need to show the user ID in a text box and write "SomeUser Connected!" (Replace SomeUser with the ID), this is the sub:
    Code:
        Public Sub onConnection(ByVal ID As String) Handles Host.onConnection
            TextBox1.AppendText(ID & " connected" & vbNewLine)
        End Sub
    Now the problem is that my textbox only shows "SomeUser" and doesn't continue the string as it should display: "SomeUser connected".

    Any ideas how it happens? it seems that everything is fine!

    Thank you very much!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Cannot use "Byval" string to connect with strings

    The code itself is fine for appending the text, so there is something else going on.

    Did you set a breakpoint and step through the code?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: Cannot use "Byval" string to connect with strings

    Quote Originally Posted by kleinma View Post
    The code itself is fine for appending the text, so there is something else going on.

    Did you set a breakpoint and step through the code?
    I actually did, and it put it took me to the class I built after the end sub here is the "step into" log:
    Code:
    Step into: Stepping over non-user code 'System.Windows.Forms.NativeWindow.DebuggableCallback'
    Step into: Stepping over non-user code 'System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop'
    I have got to mention that I don't have any errors displayed so it's a bit wierd because the data in the "ID" value is correct by somehow it doesn't add the " connected" string. The only possible problem maybe is the class but I can't see the problem everything seems to work fine.

    The class I built "NetComm" uses multithreading with the syncronnizecontext (context.post), maybe it should help.
    Last edited by shynet; Oct 20th, 2009 at 10:22 AM.

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Cannot use "Byval" string to connect with strings

    VB.Net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Test("dee-u" & Chr(0) & " of vbforums")
    3.         Test("dee-u of vbforums")
    4.     End Sub
    5.  
    6.     Private Sub Test(ByVal ID As String)
    7.         MessageBox.Show(ID & " connected!")
    8.     End Sub
    I can only guess that the ID is null terminated.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: Cannot use "Byval" string to connect with strings

    Quote Originally Posted by dee-u View Post
    VB.Net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Test("dee-u" & Chr(0) & " of vbforums")
    3.         Test("dee-u of vbforums")
    4.     End Sub
    5.  
    6.     Private Sub Test(ByVal ID As String)
    7.         MessageBox.Show(ID & " connected!")
    8.     End Sub
    I can only guess that the ID is null terminated.
    Thank you very much!

    If I was right the problem was when I converted the bytes I got to string using the System.Text.Encoding.GetString(bytes) which added chr(0), I made a function that "chop" the chr(0) and that fixed my problem, thank you!

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [RESOLVED] Cannot use "Byval" string to connect with strings

    Glad it gave you a hint. =)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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