Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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.
0
xr62002
Asked:
xr62002
  • 3
  • 3
  • 2
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now