Help !!
I'm working on something in VB.NET where I been to use a function…
I understand that I need…
Public Sub WriteMessage(ByVal amessage As String)
' Stuff Goes Here
End Sub
But when I try to do something like…
Public Sub WriteMessage(ByVal amessage As String)
TextBox1.Text = amessage
End Sub
I get an error… what do I need to do?
DarkPanther_ wrote: Here's what it says:
Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.
Weren't you setting the Text of a TextBox in the initial post?
Anyways, are you creating the label dynamically at runtime? Multi-threading? If yes to both, you'll need to create the label as an object in a class so that the other threads can access it. Otherwise, I have no idea, really. If you're creating the label in the VS GUI interface, then you can access that from other threads… even other forms.
k,
let's say…you have a project… 2forms… if you want a textbox1 from form1 to send text on command1_click() to a label1 on form2 you do:
private sub command1_click() form2.label1.capition = form1.text1.text end sub
this is just an example,yes? :) you can also use public subs…and put some functions in there to access from any thread,or form or whatever…but i am not gonna type a tutorial of a few hours reading in here :P also i noticed you typing plain text in the source without quotes? you might want to try to put it inbetween (double) quotes…
you can pm me,if you have any questions…or try to find my msn address somewhere ;) it might be on my site…
peace.
darksun wrote: k,
let's say…you have a project… 2forms… if you want a textbox1 from form1 to send text on command1_click() to a label1 on form2 you do:
private sub command1_click() form2.label1.capition = form1.text1.text end sub
this is just an example,yes? :) you can also use public subs…and put some functions in there to access from any thread,or form or whatever…but i am not gonna type a tutorial of a few hours reading in here :P also i noticed you typing plain text in the source without quotes? you might want to try to put it inbetween (double) quotes…
you can pm me,if you have any questions…or try to find my msn address somewhere ;) it might be on my site…
peace.
Mostly on point, but the Label object also uses .Text… don't remember it using Caption, unless it's an earlier version of VB.
Also, he doesn't need quotes around it, because it wasn't plain text… he was passing in a String by value, so he's using the variable name.