|
-
Oct 20th, 2009, 09:40 AM
#1
Thread Starter
Addicted Member
[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!
-
Oct 20th, 2009, 09:49 AM
#2
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?
-
Oct 20th, 2009, 10:04 AM
#3
Thread Starter
Addicted Member
Re: Cannot use "Byval" string to connect with strings
 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.
Last edited by shynet; Oct 20th, 2009 at 10:22 AM.
-
Oct 20th, 2009, 10:25 AM
#4
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.
-
Oct 20th, 2009, 11:36 AM
#5
Thread Starter
Addicted Member
Re: Cannot use "Byval" string to connect with strings
 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!
-
Oct 20th, 2009, 11:53 AM
#6
Re: [RESOLVED] Cannot use "Byval" string to connect with strings
Glad it gave you a hint. =)
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
|