Running Code When App Starts

I"m just starting with Xojo. I’ve spent many hours with PowerBASIC.

Entering code for a button event seems to be pretty straightforward with Xojo.

But, what about code that needs to run when an application is first started? Where is that code placed?

Also, where is code placed that I have had in subprograms for functions in PowerBASIC?

If someone can point me to any examples or documentation that answers the above questions, that would be great.

John Rayfield, Jr.

Sounds like you want the Open event on the App object.

https://documentation.xojo.com/topics/application_structure/desktop/desktop_apps.html

You’ll typically use Classes or Modules for your code methods:

https://documentation.xojo.com/getting_started/using_the_xojo_language/methods.html

For reference, the full User Guide is here:

https://documentation.xojo.com/getting_started/introduction/what_is_xojo?.html

2 Likes

He is right.

Also, welcome. :slight_smile:

Every control (object) that you add to your layout will most likely have its own Open event handler, so you put initialisation code that is specific to that object, in its Open event handler.

I understand. But, I do want some code to run, before anything else happens, other than the program being executed.

John

Hi John,

By default, an “App” object is added to the Navigation view of each Desktop project.

Right-click on the “App” object, choose “Add to…” & “Event Handler” and select the “Open” Event.

The App.Open Event is basically executed as soon as your application starts up, before any windows or controls appear. See Application for more information on the “App” object.

I hope that is what you’re looking for.

1 Like

It would be helpful to know what you are wanting this code to do.

Thanks Scott. This is exactly what I’m looking for!

John

John - I think your question was answered, but here is what I do to get the job done you are asking about:

Thanks Barton. This just further helps me to better understand the overall ‘layout’ of a program in Xojo. Right now, that’s probably the biggest difference that I’m seeing between Xojo and PowerBASIC. And I think I need to look over more of the example applications that I can find online, to better help me to grasp this.

John

Just so you know, there’s a huge collection of examples bundled with Xojo.
Check the “Example Projects” folder.

Thanks Tim. Yes, I’ve found those. I’m also looking for any other example programs that I can find, too.

John