In an application I'm developing, I'm starting a thread from main form. That thread calls a function from within a module.
In the main form, I want to update the text of a label while the function is executing.
From within the function, I have a Do...Until statement. Inside the do...while, I have a char variable which changes value. I want to pass that value (single char) back to the main form....
Here's what I'm trying...
Form1.vb has the label.
I start the thread:
t1 =
New Threading.Thread(New Threading.ThreadStart(AddressOf Go))t1.Start()
Module.vb has the Go() function:
Each
y In strLessonDo
For Each y in string
Form1.Label18.Text = y.ToString
Next
Loop Until blah blah blah
I've obviously left a lot of meat out, but this is essentially what I'm trying to do.
If I include a MsgBox statement within the For/Next to show the value of Y, the MsgBox indeed shows the correct character. However, the label never updates from it's original value. The label.enabled property is set to true. label.visible is also true. I've also tried using Form1.Label18.Text = y
Neither of these
Form1.Label18.Text = y.ToString
or
Form1.Label18.Text = y
will change the value of the text of the label in my Form1.
What am I missing
Thanks
Ted

Change Label.text from within a module?
mk20
Hi James and thanks for the reply.
Your example wouldn't apply because the "Me.Label18.text =" would imply that the label is within the same form. However, I'm trying to change the text in a form from within a module.
Thanks
Ted
dlippiet05
You are correct. You would need to reference the form where the Label is located. My bad. But, still using the code you posted, I don't see where y gets it's value ( unless that was a typo) so the value could never be passed to the form from your module if y doesn't have an assigned value.
Check out this series of posts I found using Google, maybe they will help you.
http://groups.google.com/group/microsoft.public.dotnet.framework.compactframework/browse_thread/thread/de6e790c6d50f83c/fc837d19bbc2bca0 lnk=st&q=update+a+label+%22VB.NET%22+(Thread+OR+Value)&rnum=12&hl=en#fc837d19bbc2bca0
james
aka:Trucker
evslin
Thanks James. Let me bookmark that and read it during my lunch break at work and see if that'll work.
Ted
WIPIT
I don't see where you are assigning a value to Y. But, if it correctly passes the values you expect to the Messagebox, then there is a problem ( obviously). But, you need to at least show where Y gets it's value to help us help you determine the problem.
Unless it is happening here:
For Each y in string
Form1.Label18.Text = y.ToString
Next
Loop Until blah blah blah
Should that be:
For Each y in strLesson
me.Label18.Text = y.ToString
Next
The difference in your code I see is in the For Each y in ..... statement. It should be as I put in the second example, For Each y in strLesson ( I'm assuming that strLesson is the variable that holds the values you are assigning to y)
james
aka:Trucker
K wing Chan
Hmmmm, well that got me started on the right track. Here's my code now...this is inside the module:
sub lesson()
'strLesson is array of text read from a resource.
Do
For Each y In strLessonwavchr(y.ToString())
SetText(y)
Next Loop Until strLesson.EndsWith("[")MsgBox(
"Lesson Complete", MsgBoxStyle.Information, "Information")t1.Abort()
End Sub Delegate Sub SetTextCallback(ByVal y As String) Private Sub SetText(ByVal y As String) If Form1.Label18.InvokeRequired Then Dim d As New SetTextCallback(AddressOf SetText)Form1.Label18.Invoke(d,
New Object() {y}) ElseForm1.Label18.Text = y
End If End SubBut, this isn't working either. I got this info from:
http://msdn2.microsoft.com/en-us/library/ms171728(en-US,VS.80).aspx
monyplaba
Well, I tried different routes and variations off what they show in this article, but I couldn't get it to work.
Ted
casperOne
Ok, I've got a million of them!!
http://www.startvbdotnet.com/threading/default.aspx
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=60994&SiteID=1
And then there's this:
http://search.microsoft.com/results.aspx mkt=en-US&q=Threading&first=11&FORM=PEME
I think the first link will help you the most. Some of the others are C# samples but, can be converted if needed.
james
aka:Trucker