Is there a way to run a sub on a form by calling it from another form?
Printable View
Is there a way to run a sub on a form by calling it from another form?
If you declare the Sub public, you can call it from anywhere. Ex:
Say we want to call it from Form2:VB Code:
Public Class Form1 Public Sub HelloWorld() MsgBox("Hello World") End Sub End Class
VB Code:
Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim frm1 As New Form1 frm1.HelloWorld() End Sub End Class
Forms are objects, just like any other. Any object can call any accessible member of any other object PROVIDED that it has a reference to that object. Forms are no different. I suggest that you read the "Forms in VB.NET" tutorial in my signature.
thanks for the help both of you.