use control from module

this is probably a very simple question

i just got vb.net enterprise architect edition and im having a hard time getting my head around all the new features

how do i access a control on a form through a module

like in vb6 for example it was form1.winsocksend.senddata data

how do i do this in vb.net

thanks --Laser--
LVL 4
--laser--Asked:
Who is Participating?
 
arif_eqbalCommented:
If you are calling the Module method from Form1 and the Winsock Control is on Form2 then I am afraid you can't pass the object as an argument because Form1 will have the same problems accessing Winsock as the Module is having

What I can suggest is have a module Level variable in your module and on the Form Load of form2 set it equal to your winsock object

Now Module will use this control through the object reference in the variable.

Also on Closed event of Form2 set the module variable to Nothing.

And be careful in you module do error checcking before using the variable whether it references to the control or it is Nothing.

0
 
RonaldBiemansCommented:
Well you could give the sub the form as an argument
or set the form as a global variable
or if you know the window handle to could get it that way
0
 
--laser--Author Commented:
isnt there anything simpler like form1.winsocksend.senddata data


i have this code in vb6 and need it to run in vb.net

public sub Send (data as string)
    form1.winsocksend.senddata data
    doevents
end sub


this code is just in a module
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
RonaldBiemansCommented:
No sorry, Vb6 and VB.net are very different in that aspect. But if you set form1 as a global variable you could do it that way
0
 
--laser--Author Commented:
how would i set it as a global variable, as i said i am very new to vb.net

thanks
0
 
RonaldBiemansCommented:
Just a couple of questions, because setting a form as a global variable isn't actually the proper way to do things in .net, it is just a workaround.

Is your form1 your startup form ?
When and where are you calling the sub in your module
0
 
arif_eqbalCommented:
I posted a comment on your earlier message

Pass the object of Winsock to the function in the module that's the most elegant and easy way.

If there's any hitch in it you can post the specific detail
0
 
--laser--Author Commented:
ronaldbiemans

form1...yes it is startup
i call the sub in the module whenever i want to send a string through the winsock control
its just easier then typin winsocksend.senddata data
doevents
every time i want to send something because there is a lot of things to be sent


arif egbal, could you show me an example of how to pass the winsock to the fuction in the module please

im just getting used to vb.net and it is a lot diffrent to vb6 so im sure you understand if im asking silly simple questions :-)
0
 
RonaldBiemansCommented:
do you call the sub in the module just from form1 or from different forms?
0
 
--laser--Author Commented:
hmm....

actually it will be 2 seperate forms form1 and form2 but the winsock control resides on form1
0
 
--laser--Author Commented:
ok i have changed my mind this sounds a bit to complicated for me at this stage

i will put the sub into form1 and leave out some features on form2

only thing is that doevents doesn't work in vb.net ! !

is there still a need for doevents command?
0
 
--laser--Author Commented:
ok i worked that one out...        System.Windows.Forms.Application.DoEvents()
0
 
arif_eqbalCommented:
You already have the reference to
System.Windows.Forms

So just Application.DoEvents() will do
0
 
--laser--Author Commented:
i tried that already but it didnt seem to work,anyway the long way works so im happy :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.