Question How to link two forms in VB??

Mayank Chugh

New member
Joined
Apr 29, 2011
Messages
1
Location
New Delhi, India, India
Programming Experience
Beginner
Hi I'm new at VB and I am assigned to make some modifications in a simple game developed using VB...for the desired changes, i have to create a new windows form , put some buttons on it and link them to the main and other subroutines in existing windows form.

Is there anyway to redirect to the main windows form and main subroutines on the click of button on new form??

Making the existing subroutines "public" didnt work!!
 
You can try putting the subroutines in a module, or if you create a new instance of that form and then use the methods it should work. Otherwise you can make it "Shared"

Some Examples: creating a new instance

VB.NET:
Public Class frmOld
    Sub doSomething()
        MessageBox.Show("Wee")
    End Sub
End Class

Public Class frmNew
    Dim old As New frmOld

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        old.doSomething()
    End Sub
End Class

or you can use the shared and not have to create a new instance of the class

VB.NET:
Public Class frmOld
    Shared Sub doSomething()
        MessageBox.Show("Wee")
    End Sub
End Class

Public Class frmNew
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frmOld.doSomething()
    End Sub
End Class


I think this is what your talking about?

"Is there anyway to redirect to the main windows form and main subroutines on the click of button on new form??" -this sentence is kinda of confusing to me.. but if i am understanding it correctly, it looks like you can just try adding "Shared" like in the example above and it should do the trick


a little reference i found online about access specifiers for you Data Types, Access Specifiers in VB .NET
 
Back
Top