switching between open forms

bones

Well-known member
Joined
Aug 23, 2014
Messages
143
Programming Experience
Beginner
In it's current state, my app will display multiple forms at the same time but you can only access the last form opened. How does one allow for having multiple forms open and allow switching between them?
 
What you're doing looks like it should be fine so either you're doing something wrong without realising it or something is broken in your project.

One possibility is that you think you're using the default instance but you actually aren't because you have declared a variable with the same name as the type and are therefore using that. In this code:
VB.NET:
    Private Sub OrificeCalculationsMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrificeCalculationsMenuItem1.Click
        'orificeflowcalcs.ShowDialog()
        [B]orificeflowcalcs[/B].Show()
    End Sub


    Private Sub ConfigurationsToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurationsToolStripMenuItem.Click
        'configurations.ShowDialog()
        configurations.Show()
    End Sub


    Private Sub CalculationToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculationToolStripMenuItem.Click
        'databasefields.ShowDialog()
        databasefields.Show()
    End Sub
you should right-click on the `orificeflowcalcs` and select `Go to Definition` or the like. If that navigates to a variable then that's your issue. If it doesn't then something in your project is broken and you may have to recreate that form.

I found the problem. ... thanks for the help and pointer...
 
I found the problem. ... thanks for the help and pointer...

For our own interest, can you let us know what the issue was? Was it that you did have a variable with that name or something else? If that was the issue then it's another black mark for default instances. They were added to make life easier for beginners and also to make some VB6 code convert more painlessly but this may be yet another example of how they can cause just as many issues as they solve because people don't understand what they are and how they fit into the grand scheme of things.
 
For our own interest, can you let us know what the issue was? Was it that you did have a variable with that name or something else? If that was the issue then it's another black mark for default instances. They were added to make life easier for beginners and also to make some VB6 code convert more painlessly but this may be yet another example of how they can cause just as many issues as they solve because people don't understand what they are and how they fit into the grand scheme of things.

I had a declaration at the beginning of the class code. [Public orificeflowcals as new orificeflowcalcs ]..or something to that affect. I must have tried adding that when the problem first surfaced. Somewhere I read some information that must have indicated I needed such a statement because I certainly wouldn't have thought of adding it on my own...

If when pasting code to the form the colors of words in the code remained entact, you would probably have spotted it in a nanosecond. All the other form.show code had the form name in blue but the name in the .show code for that form was in black. I never noticed that until you pointed out "default instances" and even then I didn't spot it straight away. It was what default instances was showing that led me to the source of the problem....was different than all the others.

Simple but stupid mistake for a novice to make....
 
Back
Top