Application Launch Question

Hello, I am new to XOJO, ive heard many good things about it and thought i try it on a project im working on.

Ive created a window1 with many action buttons, menu, etc

I would like to know if its possible to instruct it when launched to look for a specific file, IF that file is not found to launch my Window1… IF that file is found i would like to run a few commands automatically. Thank you in advance.

Sure. Add your Code in the App.Open Event.

[code]If stuff-i-want-to-chek-is-looking-good Then

Window1.Show

Else

Run-a-few-commands

// and now open a Window or Quit or … :slight_smile:

End If[/code]

@Sergio Campos — I agree with Sascha, but note that “Window1.Show” will have a quite different behavior than “Window1.Visible = True”. The latter is probably the one you want to use (but it is not related to your original question).

And welcome to Xojo!

Would i use FolderItem?

In my window there is six buttons, Each button runs a different command and at the beginning i have it creating a Folder with a file.

dim f as FolderItem
f = SpecialFolder.Applications.Child(“MyFolder”)
f.CreateAsFolder

dim db as new SQLiteDatabase
db.DatabaseFile = f.Child(“MyFile”)

When the application runs again i would like for it look for MyFolder. If My Folderr not found show window1.

If MyFolder found, distinguish which file has been created from the first time a button was selected and run that command automatically everytime there after until the folder gets deleted manually.

You should always check wether your folder or file exists to avoid unhandled error:

[code]//First we DO NOT use /Applications to store data. We’ll use “myApp” folder in ApplicationSupport
dim fold as FolderItem = SpecialFolder.ApplicationSupport.Child( “myApp” )
if NOF fold.Exists then
fold.CreateAsFolder
end if

dim f as FolderItem
f = fold.Child(“MyFolder”)
if NOT f.Exists then
f.CreateAsFolder
//<<< Add anything you want to execute here
else
//<<< What to do if the folder already exists?
end if

dim db as new SQLiteDatabase
db.DatabaseFile = f.Child(“MyFile”)
if db.CreateDatabaseFile then //The database file was successfully created OR opened
//<<<< Do something here
else
// ERROR
end if[/code]

Let me just go thru it to see if i understand

dim fold as FolderItem = SpecialFolder.ApplicationSupport.Child( “myApp” ) //This is looking for /creating folder called myApp
if NOF fold.Exists then // If folder myApp is not there
fold.CreateAsFolder // Create the folder
end if

dim f as FolderItem
f = fold.Child(“MyFolder”)
if NOT f.Exists then // If MyFolder does not exist Create it?
f.CreateAsFolder

//<<< Add anything you want to execute here
// Would i add MainMenu.show <---- to display my app window? MainMenu is what i named it.

else

//<<< What to do if the folder already exists?

// If My Folder exist i would want it to look for a config whether if is a.config, b.config, c.config., d.config., e.config, or f.config.
// once config file is found lets say b.config can i add Methods in this portion to run?

end if

dim db as new SQLiteDatabase
db.DatabaseFile = f.Child(“MyFile”)
if db.CreateDatabaseFile then //The database file was successfully created OR opened
//<<<< Do something here
else
// ERROR
end if

Instead of a SQLiteDatabaseFile i changed it to a config

dim f as folderitem = a.Child(“a.Config”)
dim tos as TextOutputStream = TextOutputStream.Create(f)
tos.write “A Config file for MyApp, Please do not delete”
tos = nil
f = nil