|
-
Nov 5th, 2009, 05:25 AM
#1
Thread Starter
Addicted Member
Odd Code Problem
Hey Ive been racking my brains trying to figure out why my vb is acting like this and by this i mean
Code:
Private Sub DoListen()
constate = "Awaiting Connection"
Do
Try
constate = "Connection Established"
Dim tcpClient As TcpClient = listener.AcceptTcpClient()
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
While networkStream.CanRead
Do
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
command = clientdata
thats just part of the do listen sub, which works perfectly.
but the problem is constate I have a timer which is enabled and started with a interval of 100 and the code on that is
textbox1.text = constate
but it doesnt change at all, before constate i was inserting textbox1.text = "connection....." but that didnt work either, only msgbox seemed to work, does anyone know what is wrong or waht would cause such a odd occurance?
-
Nov 5th, 2009, 05:38 AM
#2
Re: Odd Code Problem
Using a Timer for that is a hack anyway. When constate changes you should simply call a method that will explicitly update your TextBox:
vb.net Code:
Private Delegate Sub UpdateTextBoxCallback(ByVal text As String) Private Sub UpdateTextBoxCallback(ByVal text As String) If Me.InvokeRequired Then Me.Invoke(New UpdateTextBoxCallback(AddressOf UpdateTextBoxCallback), text) Else Me.TextBox1.Text = text End If End Sub
Now you just do like this:
vb.net Code:
Me.UpdateTextBox("Connection Established")
-
Nov 5th, 2009, 06:23 AM
#3
Re: Odd Code Problem
I think jmcilhinney was a little fast there, the example above might give you some errors. Try this instead 
vb.net Code:
Private Delegate Sub UpdateTextBoxCallback(ByVal text As String) Private Sub UpdateTextBox(ByVal text As String) If Me.InvokeRequired Then Me.Invoke(New UpdateTextBoxCallback(AddressOf UpdateTextBox), text) Else Me.TextBox1.Text = text End If End Sub
-
Nov 5th, 2009, 07:54 AM
#4
Re: Odd Code Problem
 Originally Posted by _powerade_
I think jmcilhinney was a little fast there, the example above might give you some errors. Try this instead
vb.net Code:
Private Delegate Sub UpdateTextBoxCallback(ByVal text As String)
Private Sub UpdateTextBox(ByVal text As String)
If Me.InvokeRequired Then
Me.Invoke(New UpdateTextBoxCallback(AddressOf UpdateTextBox), text)
Else
Me.TextBox1.Text = text
End If
End Sub
Good point. That's what happens when you type straight into the forum instead of into the IDE and then copy and paste.
-
Nov 5th, 2009, 11:42 AM
#5
Re: Odd Code Problem
Well, it felt good correcting one of the pro's
Last edited by Arve K.; Nov 5th, 2009 at 08:45 PM.
-
Nov 5th, 2009, 01:26 PM
#6
Thread Starter
Addicted Member
Re: Odd Code Problem
ahhh so thats the pro way to do it =) thankyou both works like a charm
-
Nov 5th, 2009, 08:47 PM
#7
Re: Odd Code Problem
Remember to mark as resolved
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
|