Accessing form controls within a private shared sub


New member
Oct 20, 2004
Petit-Rocher, NB, Canada
Programming Experience

How can I access a form control, let's say a textbox, within a private shared sub?

My situation: I'm learning about Async Sockets (server) and I want to insert the received text by the server in a textbox on my form. I read something about creating a delegate sub, but it wasn't very clear and helpful. So if anyone could help me with this, I would be very :) Thanks.

Try this:

My understanding in theory is that you are not supposed to access the properties of a control on a form directly. Thats why all the items on a form are private. You can however create a Public function in the form that contains the control that will set the text property, then access it like you would an accessor function of a class. I.E.

Public Function setTextBox1(item as string) as boolean
textBox1.text = string
return 1

now you can set the text of the textbox. The other option is to make the textbox control public in the declaration of the form, but I guess thats a no, no.
when you declare a new frmMyform as form

mystring = frmMyform.textbox1.text

- or -
frmMyform.textbox1.text = mystring

and if you want to get to your main form from a secondary form, in a module declare a myMainForm as new mainform

then on mainform_Load:
myMainForm = me

secondary form:
mystring = MyMainform.textbox1.text
- or -
MyMainform.textbox1.text = mystring