Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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--
0
--laser--
Asked:
--laser--
  • 7
  • 4
  • 3
1 Solution
 
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
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
--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
 
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
 
--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.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now