Why does this example not come up??

UCM

Centurion
Joined
Jan 1, 2003
Messages
135
Location
Colorado, usa
How to have 1 instance of 2x forms and switch between them...

Please see posts below....





* Attachment deleted by UCM * please see post below, thank you....
 
Last edited:
I downloaded and ran it and nothing of what you mentioned
happened. You may want to create a new project and try again.

This was one thing I noticed, however. When you are "switching"
from Form1 to Form2, you need to declare a NEW instance of
Form2 before you can show and hide it. This can be done in the
declare (Dim myForm2 As New Form2). The same holds true for
the myForm1 variable on Form2.
 
Crap, wrong exapmle lol...

sorry, I uploaded the wrong example....

the example I have the above issue with is the one where I use a module to control both instances of the forms....

Thanx for your input on the above example though, that helps with it....
 
Last edited by a moderator:
Before I even opened the project, I had a hunch about what was
wrong, because it's a common problem that I myself have made.

Since a Windows application needs to have a continuous
message pump, and a window to handle it, you cannot use a
simple Form.Show() to show a new instance of a form when your
application starts from Sub Main. Instead,
you need to tell the application to send Windows messages to
a specific form. To do this, use the Application.Run() method.

After the form closes (and is destroyed and its message pump
destroyed), the code will return to the Sub Main and continue on
the next line of code.

This is what you currently have:
Visual Basic:
  Public Sub Main()
    myForm1.Show()
    myForm1.TextBox1.Focus()
  End Sub

This is what you need:
Visual Basic:
Public Sub Main()
  Application.Start(myForm1)
  ' Put the code to focus TextBox1 in the Form's load event
End Sub

The rest of the code in the module will work fine.

I should point out that it is better OOP practice to shun the use
of modules and instead use shared (aka static) method of classes.
You may want to try this in the future.
 
How would I apply the good OOP practice you're mentioning to the first example I uploaded before in error?

In case you deleted it, here it is again...

btw, I would much rather avoid using modules but to get it with just 1 instance of each form, I wound up having to use the module....Of course, I fyou can help me get the below example to work without a module then you will of made my week :)
 

Attachments

Last edited by a moderator:
You _never_ need to use modules. Your Sub Main can go in any class you like, as long as you make sure it has the Shared modifier in its declaration.

Also, please don't include binaries in attachments.
 
Any idea how I can make the above example "accessmultipleformsincodewithoutamodule.zip" work with just 2 forms and no modules or sub mains?

I thought I did it once before, but when I looked at the old example I put in moff balls, it haed a module run with sub main, oyy....

I'll use a sub main if I have to, bout I would like to not have to use it....

All I need is just 1x instance each of 2 different forms and be able to call each other form from the other...

btw, VolteFace helped me get this idea to work in This Thread but we're still using a module...

I would love to ditch the module altogeather, but if that isn't going to acheive the desired result of each form keeping their values and contents then I'll settle for the module and build my project around that...

Thank you everyone very much for your help on this, I really appreciate it :-)
 
Last edited:
Back
Top