Solved: Getting and Setting global Vars from a db table
Posted: Tue Nov 26, 2019 12:06 pm
Hi there,
I'm building an app that saves the users default settings / preferences in an SQL table. The table contain things such as preferred date format , region etc. The table looks something like this below
So far I have not found a way to refer to the value of a variable as a it's own declared variable - so although I can see that the value of varName in row 1 is gLocale I can't get LiveCode to set gLocale to anything dynamically. The only (and distinctly clunky) way I've got around this so far is to add If statements in the repeat loop but this would restrict the creation of variables and I'd have to add more "if"'s every time I add a new row to the table as per below.
eg
Anyone know if it's possible to extract the value of a variable and use it as the name for another variable and set it?
Thanks,
Al.
I'm building an app that saves the users default settings / preferences in an SQL table. The table contain things such as preferred date format , region etc. The table looks something like this below
I'm using a simple repeat loop to grab the data from the table, and then I want to dynamically set the variables that are declared within it.Row | varName | varValue
1 | gLocale | E
2 | gRegion | UK
Code: Select all
put "SELECT * FROM appSettings" into tSQL
put revDataFromQuery("§",,gdbid, tSQL) into tData
repeat with r = 1 to the number of lines in tData
-- Pseudo code below
-- put item 2 of line r of tData into the variable named in item 1 of line r of tData
-- eg put 'E' into gLocale
-- eg put 'UK' into gRegion
end repeat
eg
Code: Select all
If item 1 of line r of tData = "gLocale" then
put item 2 of line r of tData into gLocale
end if
if item 1 of line r of tData = "gRegion" then
put item 2 of line r of tData into gRegion
end if
etc
Thanks,
Al.