Close method in Open event

I have read earlier posts in this forum and understand that the Close method does not work in the Open event.
The close method leaves an empty window on the screen.

I need to run a bunch of code in the window, but with the window in an invisible state under certain conditions.
Once the code has been executed, the window is closed.
Is there any other way to achieve it ?

Maybe, not opening the window until it’s really needed for a display?

i would check the condition first and only open the new window if condition is meet.

My application contains several windows that have several methods each. The names of these methods are same in all windows. So to do a particular task I have to use the bunch of methods from a particular window.

That is the only reason, I wish to open the window in an invisible condition is to use the code available in the window without any user interaction.
It should be transparent to the user.

Any other solution please ?

I would try to move the code in question out of the window so that it can be called independently. Creating an invisible instance of a window just to run some code in it could be a symptom of bad design.

Why do you need a window? Why not app.open?

Why not have the methods in the app or a module?

[quote=369124:@Chellappan Palaniappan]My application contains several windows that have several methods each. The names of these methods are same in all windows. So to do a particular task I have to use the bunch of methods from a particular window.

That is the only reason, I wish to open the window in an invisible condition is to use the code available in the window without any user interaction.
It should be transparent to the user.

Any other solution please ?[/quote]
Instead of a Window, just create a class with your methods and then you’ll do something like this:

dim runner as New CustomClass Runner.RunMethod()

[quote=369133:@Greg O’Lone]Instead of a Window, just create a class with your methods and then you’ll do something like this:

dim runner as New CustomClass Runner.RunMethod()[/quote]

Why a class? Why not call RunMethod direcly? Seems like unnecessary overhead to me, but since you know a lot more about programming than I do, I have to ask why …

Because you would replace each window with a separate class, all of which implement a class interface which you call.

dim runner as RunnerInterface
select case X
case A
   runner = new classA
case B
   runner = new classB
case C
   runner = new classC
end
runner.RunMethod()

That again looks like unnecessary overhead. Why not

Select Case X Case A RunMethodA Case B RunMethodB Case C RunMethodC End

It reads like Tim and Greg are trying to get the code off of the window into a class, so that the code may be run without the window. Using an interface as Tim suggested would open the code to being more flexible, which may lead to needing less copy/paste code.

There’s more than one way to accomplish most things in Xojo.