A few things I can see:[quote=44622:@Mark S]Sub Open()
dim w1 as new Window1
End Sub
A global property in App
w1 As Window1
[/quote]
You have created 2 different variables, a global one in the App, and a local one in the Open event. They are not the same. Remove the ‘Dim’ statement in your ‘Open’ event
]Sub Open()
w1 = new Window1
End Sub
Also, is ‘Window1’ the default window in the app’s properties? It will automatically open a new window instance on startup, and you are opening a second one in the Open event.
Ah HA! They are really modules. That explains it. Thank you Norman.
I have two more questions.
From above: [quote]Window1 is the default window. So does this mean the default window cannot be manually instantiated?[/quote]
Assuming w2 has been explicitly instantiated and w2 is holding the last reference to an instance of Window2 … After executing self.Close, why does a check on w2 (it’s last reference) not Nil?
If you set the App’s default window property to NONE then in the open event you can instantiate whatever window you want
When you set it in the IDE that just does it automatically when the IDE opens
Sub Action()
If w2 = Nil Then // If there wasn't one previously then we need to create one
w2 = New Window2 // Creates a reference to a new Window2 window.
End If
w2.Show
End Sub
In the Window2 Close event I have:
Sub Close()
self.Close
End Sub
When I click on PushButton1 the very first time, w2 shows. After I close w2, any clicks on PushButton1 will not show w2.
EDIT: To clarify, after the first click it’s not Nil, so it never creates a new instance. However, w2.Show does not show anything.
[quote=44729:@Mark S]In this simple case, I’m trying not to open up a new w2 if one already exists. I guess you can’t do that reliably by checking Nil then.
Although, it could never happen in this simple app, I wouldn’t want multiple w2’s open and shown to the user at the same time.[/quote]
AH
Try checking to see IF an instance already exists with
For i as integer = 0 toWindowCount-1
if window(i) isA Window2 then
// there is one already so show it
window(i).show
return
end if
next
// there isn't one
// so do whatever you need