Hello all,
I am new to XOJO and have a problem that I can’t solve.
I want to store the initial settings of radio buttons in a small sqlite database. I know how to set the initial settings of radio buttons via the on/off switch of the “initial state” section but I want to control it via a database to keep it variable for a user so to say as “user settings”.
If the program starts and the window opens it checks if the settings_database.sqlite exists. If not: the database will be created and one record with integer values will be written. If the database exists: The one record will be read and according to the value of a database field (0 or 1) a radio button should set to “false” or “true”. The strange thing is: Reading the record works. Setting the radio button to “false” or “true” generally works. But both steps consecutive do not work together as shown in my code below. I think the problem is related to the event handler “open”. Has anyone an idea how to make that piece of code work?
[code]dim f as FolderItem = GetFolderItem (“settings_database.sqlite”)
dim sdb as new SQLiteDatabase
dim sdbsql as string
dim rssdb as RecordSet
sdb.DatabaseFile = f
if not f.Exists then
If sdb.CreateDatabaseFile Then
sdb.SQLExecute(“CREATE TABLE Settings(rbtWeight_0 INTEGER, rbtWeight_1 INTEGER, rbtElevation_0 INTEGER, rbtElevation_1 INTEGER, rbtPressure_0 INTEGER, rbtPressure_1 INTEGER, rbtTemperature_0 INTEGER, rbtTemperature_1 INTEGER)”)
Dim row As New DatabaseRecord
row.Column(“rbtWeight_0”) = “0”
row.Column(“rbtWeight_1”) = “1”
row.Column(“rbtElevation_0”) = “1”
row.Column(“rbtElevation_1”) = “0”
row.Column(“rbtPressure_0”) = “0”
row.Column(“rbtPressure_1”) = “1”
row.Column(“rbtTemperature_0”) = “0”
row.Column(“rbtTemperature_1”) = “1”
sdb.InsertRecord(“Settings”, row)
If sdb.Error Then
MsgBox("DB Error: " + sdb.ErrorMessage)
End If
end if
end if
sdbsql = “SELECT * FROM Settings”
dim datasdb as RecordSet
sdb.DatabaseFile = GetFolderItem(“settings_database.sqlite”)
if sdb.connect then
datasdb=sdb.sqlselect(sdbsql)
If datasdb <> Nil Then
if datasdb.field(“rbtWeight_0”).Value = 0 then
rbtWeight(0).value = false and rbtWeight(1).value = true
else
MsgBox("Connection error: " + sdb.ErrorMessage)
end if
end if
end if
[/code]
Thank you very much in advance and best regards from Germany,
Gerson Nerger
Edit (Paul): Added Code formatting tags per Post Formatting Tips.