A couple of newbie questions

  • Thread starter Thread starter melton9
  • Start date Start date
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
 
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.
 
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()
 
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.
 
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?
 
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
 
Back
Top