This code is in Form2:
VB Code:
Shared Sub Hello1() MessageBox.Show("Hello1") End Sub Sub Hello2() MessageBox.Show("Hello2") End Sub
This code is in Form1:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.Hello1() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim f As New Form2 f.Hello2() End Sub
You can call a shared method without first creating an instance of Form2, but if the method is not shared, you need an instance first. If you tried to call Form2.Hello2(), you'd get an error that says reference to a non-shared method requires an object reference.
HTH,
Mike




Reply With Quote