Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Help !!


ghost's Avatar
0 0

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?


ghost's Avatar
0 0

Does anyone know? :P


ghost's Avatar
0 0

What kind of error do you get?


ghost's Avatar
0 0

… I'm not sure it's because of the function :S

It was an error about threading or something I think :S


ghost's Avatar
0 0

Here's what it says:

Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.


ghost's Avatar
0 0

Okay… I've just played around with VB.NET a little and it seems my problem isn't the function… the info I want to be written to a label/textbox is coming from a seperate thread… what do I do?


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

very usefull your comment :S quoting me,and nothing else :S makes you look like a very smart person :happy:

and FFS do something about that rediculous sig :S jeeeeses f'n christ.


ghost's Avatar
0 0

Ignoring the part I wrote after quoting you makes you look very smart, too, genius.