Beginners question regarding switching between forms

I have only been programming with VB.NET for a few weeks with some previous experiance in VB6, but certainly not an expert.  I am trying to write a windows app that will involve a lot of changing between forms, with one form disappearing as the next opens with the hope that it will seem like one seamless window where only the controls change.  The code that I have figured out for this is something like (if I wanted to open From2 for example):

    Dim f2 as new Form2
    Me.Hide()
    f2.Show()
    'some other formatting commands here

This seems to work OK (although please tell me if there is a better way), but I would like to have this code as a seperate module so that I don't have to keep retyping with every form switch.  My main question is, if I need to dimension a new "Form2" to tell Form2 to open, how do I pass the information "Form2" to the module?  If I pass the text "Form2" as a string variable the module doesn't know it is a Type, yet I can't pass a type to the module.

Please ask me to clarify if this doesn't make sense, I apologise if some of the terminology is wrong - still trying to get my head around it all.  Cheers,

Greg.
xr62002Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NetworkArchitekCommented:
Hi xr62002,
why don't you setup a module with methods that take parameters to do all this for you?

Cheers!
0
NetworkArchitekCommented:
or well sorry, they are called functions and procedures in Visual Basic...
0
xr62002Author Commented:
That is what I want to do but cant figure out.  This is a rough version of the module code I was trying to come up with:

Module Module1
    Public Sub switchForms(ByVal form1 As String, ByVal form2 As String)
        Dim f2 As New form2
        f2.show()
        Me.hide()
    End Sub
End Module

so I was attempting to pass the names of the two forms to the module but the Dim statement sees form2 as a string variable called form2 instead of a form with the name form2
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

NetworkArchitekCommented:
Module Module1
    Public Sub switchForms(ByVal frm1 As Form1, ByVal frm2 As Form2)
        frm2.show()
        frm1.hide()
    End Sub
End Module

I not near a VS.NET box at the moment so just try that. I write some VB but I don't know all of the semantics yet
0
xr62002Author Commented:
I don't know if I am interpreting that code correctly, but wouldn't that module only work for switching from Form1 to Form2?  What if I wanted to switch from Form6 to Form7?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
xr62002Author Commented:
Just working through that code and trying to digest it.....but I'm getting the build error - "Handles clause requires a WithEvents variable" once in formA and once in formB.  Any ideas what I'm doing wrong?
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
The original author had these requirements:

>> There are 2 forms...named =>         formA  and   formB
>> and each of them have their own button named  => btnA   and    btnB

So you need a button on formA called btnA and a button on formB called btnB.

That should fix it.

Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.