A couple of newbie questions

M

melton9

I'm trying to do some things in vb.net and am having some trouble. I
generally work in VBA excel but would like to expand my horizons. I
have a couple of questions.

1.)I'm having trouble calling subs from different forms etc. I tried
making the sub public etc but still couldn't get it to recognize the
sub I needed. Do I need to set some sort of imports or something?

2.)I've seen a lot of examples with the Sub New(). Is this some
special sub with different properties or something?

Thanks
 
C

Chris Dunaway

1.)I'm having trouble calling subs from different forms etc. I tried
making the sub public etc but still couldn't get it to recognize the
sub I needed. Do I need to set some sort of imports or something?

You will have to provide a little more detail. What errors or warnings
are you getting? Can you show an example of what you have tried.
2.)I've seen a lot of examples with the Sub New(). Is this some
special sub with different properties or something?

In Vb.Net, Sub New() serves as the 'constructor' of the object, so yes
it is special in that regard. Whenever you do something like this:
Dim obj As New Foo(), you are actually calling Sub New of the Foo
class.
 
G

Guest

well if you had the sub/function "DoStuff" on form 1 and wanted to call it
from form 2, just do this:


dim frm as new Form1

frm.DoStuff()
 
M

melton9

Thanks for that, the problem is if I have stored variables in form1 and
call a sub in form1 from form 2 declaring frm as new form 1 it forgets
the stored data I have.
 
M

melton9

I just figured it out, a global variable. Its just 1 cookie type
variable I'm passing around so I'm not too worried. Heres another
quick one tho, do I need to close the created frm @ the end of the sub?
 
G

Guest

iif you dont need the form open, yes. if your only creating the form to use a
sub/function in it, why not put the sub/function in a module? that way you
can use it without creating a whole form
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top