Window opening unexpectedly

[quote=310414:@Michel Bujardet]Oh but it would. At present and even if it were invisible there is a window hanging around whatever the result of test. If find that sloppy. IMHO it would be better to create the instance in the testing code :

Public Sub test(Win as String) if 1 = 2 then Select case Win Case "frmName" dim frm as new Window2 frme.ShowModal case "otherWindow" dim frm as new Window2 frm.ShowModal else msgbox( "here" ) end if End Sub

So if the test is negative, there is no window created.

Alternatively, the window should be closed if the result is negative and the window is not needed.[/quote]

it would have NO effect on Nathans issue - absolutely none
Try your revised code with

Public Sub test(Win as String) if 1 = 2 then Select case Win Case "frmName" dim frm as new Window2 // frme.ShowModal case "otherWindow" dim frm as new Window2 // frm.ShowModal else msgbox( "here" ) end if End Sub
commented out and NO change to the visible property of either frme or frm2
They’ll show regardless of the ShowModal call

Alternately create a simple project with Window1 and Window2
Turn Window2.implicit instance OFF (dont touch VISIBLE)
On Window 1 put a button with one line in the action event

   dim w as new Window2

Run and press the button

The problem is NOT Nathans code in any way
In fact I would not do what you’re suggesting as this is a great example of whats know as “control coupling” which is NOT a good thing to strive for

Except in his present code he creates the window no matter the result. But hey, you’re the engineer.

@Michel Bujardet I think what Norman is saying is that the windows are created irrespective of the “if” or “select case” so in your example if I had a select with 100 case and therefore 100 “dim frm as new ???” where ??? are different windows then in actual fact it would create 100 instances every time the method was called. I may be very wrong but that is what I read between the lines.

I have no idea what you are planning anyway.

At the minimum, I would close the window when the test is negative. I like to clean after myself. Otherwise you may had dozen of invisible windows hanging around.

It’s not my code, do as you feel.

Michel his original code is

dim frm as new frmNewJobTicket
SecureModal frm, "itmmss-access-control-support-create-new-ticket"
frm = nil

so there’s no instance hanging around after he needs it
He creates it right where he’s going to use it (a good practice) instead of in some place remote

This has nothing to do with me being an engineer but your suggestion which DOESN’T address the actual problem which is simply solved by setting the VISIBLE property of the design in the IDE to FALSE

And that is regardless of the fact I think your suggested code is, IMHO, a bad design

I’ll see your – with a ?

:.

return