Hi Guys,
I need some help if a kind someone has a spare moment. :)
I am fairly new to VB Express 2005 (coming from MS Access) and I've just constructed a small starter program to print a currency rate that is received via an API. Now I receive the rate and assign to the text box via the following
Public Overrides Sub handle(ByVal ei As fxEventInfo, ByVal em As fxEventManager)
Dim rei As fxRateEventInfo = CType(ei, fxRateEventInfo)
If rei.Pair.Pair = "EUR/USD" Then
EURRate.EURTextBox.Text = rei.Tick.Bid.ToString
'EURRate.Refresh()
'Dim f As Form = My.Application.OpenForms("EURRate")
'f.Invoke(New UpdateTextBox(AddressOf EURRate.UpdateMessage), New Object() {Str(rei.Tick.Bid)})
End If
End Sub
The code that is commented out is other attempts to get the thing to work. These were unsuccessful. The Delegate/Invoke mechanism I found elsewhere in this forum also didn't work.
Now I know the text box receives the information because the following code executes fine
Private Sub EURTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EURTextBox.TextChanged
'This event occurs whenever a character is pressed or this box is populated automatically
Debug.Print("Text box value has changed to " & EURTextBox.Text)
End Sub
and I can see the number printed out in the debug screen every price tick but NOT in the text box itself. I can populate the box fine using a button (within the form's class) and it shows up. It also shows up when I placed the same line in a module for logging into by broker and called the module from a command button (in the form class) although there seems to be some sort of lag of a second or two between the text box showing up as being changed and the number actually appearing in the text box (I wait and wait in case of some sort of lag but still no visible price). I've also tried to assign the value to a variable before assigning to the text box (still no good). When I did another Sub to call to try and populate the text box that way it still didn't visibly populate the text box. It just seems that it doesn't want to be visible in all these instances.
Other info
MS Visual Studio Version 8.0.56727.42
MS .NET Framework Version 2.0.50727
Any advice would be much appreciated,
Drew

TextBox NOT being visibly updated
XNA Rockstar
I take it that the handle routine is not located in the EurRate form!...That being the case and as long as the EurRate form is open then try
Dim f As Form = My.Application.OpenForms("EURRate")f.EURTextBox.Text = rei.Tick.Bid
AmitKa
Thanks DMan,
Unfortunately now I get an error message:-
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
"Cross-thread operation not valid: Control 'EURRate' accessed from a thread other than the thread it was created on."
I'll spend today trying to work on it further. I had earlier thought that maybe the code should have been in the EURRate class, but then the value seems to be getting through as the TextChanged code demonstrated.
I guess my simple 3GL background is revealing itself! I'll study Threading a bit more closely today.
Thanks very much again for the suggestion.
A work around was determined:- http://forums.microsoft.com/msdn/showpost.aspx postid=795538&SiteID=1