calling public sub

wilko18

Member
Joined
Feb 7, 2006
Messages
11
Programming Experience
Beginner
I have a public sub in form2.

How can I call it from form1?

I thought if it was public it would be accessible from anywhere but
"call <name>" doesnt work, stating its not declared.
 
When you created a new form2 you got hold of a reference to that object, perhaps like this:
VB.NET:
Dim f2 As New form2
f2.Show
Now f2, you see, is a variable that keeps a reference to an instance of the object form2, incidentally the object that has got your public method. So if your public method is called "mytry" you can execute it so:
VB.NET:
f2.mytry()
 
I strongly recommend that you read this. You should also do bit of reading about object-oriented programming in general, like this. OOP is supposed to imitate the real world. In the real world could you affect an object without any way of referencing that object? No you couldn't. You'd have to have the object in your hand to do something to it.
 
Back
Top