[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!
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?
Re: Cannot use "Byval" string to connect with strings
Quote:
Originally Posted by
kleinma
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.
Re: Cannot use "Byval" string to connect with strings
VB.Net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Test("dee-u" & Chr(0) & " of vbforums")
Test("dee-u of vbforums")
End Sub
Private Sub Test(ByVal ID As String)
MessageBox.Show(ID & " connected!")
End Sub
I can only guess that the ID is null terminated.
Re: Cannot use "Byval" string to connect with strings
Quote:
Originally Posted by
dee-u
VB.Net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Test("dee-u" & Chr(0) & " of vbforums")
Test("dee-u of vbforums")
End Sub
Private Sub Test(ByVal ID As String)
MessageBox.Show(ID & " connected!")
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!
Re: [RESOLVED] Cannot use "Byval" string to connect with strings
Glad it gave you a hint. =)