Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupid Q - Call sub on another form

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Stupid question, I know, but still trying to get used to all of this.

In VB6 if I wanted to call a sub on another (unloaded) form, all I needed to do was give the form name.sub name and the form would automatically load and perform the code in the sub. Apparently now that doesn't work -- how do I make this happen in .NET?

Thanks

CraigHartz
 
You have to instantiate the form's class

Public Class Form1
Using Form2 'This is where you instantiate the other form

Sub CallForm2
Form2.SomeSub()
End Sub
End Class

Public Class Form2
Sub SomeSub
' Insert really great code here :)
End Sub
End Class
 
If its reusable code, it usually beneficial to move the code into its own code class. Making the sub or function shared also means you can call the code without instantiating the class.

Sweep
...if it works, you know the rest..
Always remember that Google is your friend

curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top