Save and reload variable when file opened

How to store a variable when the software is closed and, reload is when the software is re-opened?

I use an SQLite database for that. Save all the settings into it and reload at app startup.

(Xojo 2019r3.1 Desktop Project)

i use a Settings class

using app open & close event

Sub Close() Handles Close Settings.Save End Sub Sub Open() Handles Open Settings.Load End Sub

Protected Property SoundEnabled as Boolean = True
Method for Filename

[code]Public Function File() as FolderItem
Var f As FolderItem = SpecialFolder.ApplicationData.Child(“YourAppName”)

If f.Exists = False Then f.CreateFolder

Return f.Child(“Settings.txt”)

End Function
it use a dictionary to json

[code]Public Sub Save()
Var d As New Dictionary

d.Value(“SoundEnabled”) = SoundEnabled

Var j As JSONItem

j = d
j.Compact = False

Var st As TextOutputStream = TextOutputStream.Create(File)


End Sub
read json

[code]Public Sub Load()
Var f As FolderItem = File

If f.Exists = False Then Return

Var st As TextInputStream = TextInputStream.Open(File)

Var j As New JSONItem(st.ReadAll)


SoundEnabled = j.Lookup(“SoundEnabled”, True)

End Sub

Hello Markus, thank you! I got the app 'close, ‘open’, property and method. However, cannot seem to figure out add ‘Public sub save’ and ‘Publ;ic Sub load’. Are these classes? Thanks Naren

that is named shared method. because i need only a single instance i used it this way.
i newer apps i use JSONItem direct without Dictionary.
with .Lookup("…",value) you can set default values if key value pair not exists, that is useful if you add properties later.

Thank you! Appreciate your guidance. I Will work on this. Thanks