Page 2 of 2
Re: User Profile and User Properties DB?
Posted: Thu Feb 23, 2012 12:31 pm
by bn
Hi Barry,
Code: Select all
set the filename of stack "MyData" to gPrefsDat
save stack "MyData"
yes you have to save the stack. It will be a stack of the name
"myData" although the name of the file on disk will be
"Prefs.dat".
I don't know if this is what you want. And you probably don't want to create a stack "myData" every time you start the main stack.
you call initPrefDB on openstack. So every time you open the stack it will create a stack "myData" and save it. You might want to test for the existence of a stack "myData" before you create the stack. If the stack is there I would open the stack.
I always find it safer to enclose literals with quotes. E.g.
Code: Select all
set the text of field txtBarrysFolder to fldrBarrys
I would say
Code: Select all
set the text of field "txtBarrysFolder" to fldrBarrys
Livecode does the best it can to find out if it is a variable or a literal. But eventually you will mix up the two and get errors that are hard to track down.
Kind regards
Bernd
Re: User Profile and User Properties DB?
Posted: Thu Feb 23, 2012 9:45 pm
by BarrySumpter
bn wrote:Hi Barry,
please have a look at:
http://www.runrev.com/newsletter/januar ... p?a=NWS124
SetPref is a command the way you declared it.
Then:
If I want to change a custom property that is an
array I always take the custom property into a local variable, then change the value of the array and set the custom property to the local variable.
instead of:
Code: Select all
on SetPref pLabel, pValue
put gPrefsDat into tStack
set the uPrefs[pLabel] of stack tStack to pValue
save stack tStack
end SetPref
try
Code: Select all
on SetPref pLabel, pValue
put gPrefsDat into tStack
put the uPrefs of this stack into tArray -- local variable to hold and change array
put pValue into tArray[pLabel]
set the uPrefs of this stack to tArray -- update the custom property with the new values
save stack tStack
end SetPref
if you want to call this command you would code:
Kind regards
Bernd
Another missed post.
Sincerely Bernd. Thanks for your continued support.
I thought we had changed the command handler
on SetPref ...
to a function
Function SetPref ...
And now we're dicussing changing it back.
I think when you were writing about command you mean a command handler.
We've discussed at length that prefixes txt means text box and chk means checkbox and btn means button.
We've also established the field "data" saves only milli-seconds of execution times.
And actually takes longer to type the two ".
fresh look this mroning.
Re: User Profile and User Properties DB?
Posted: Thu Feb 23, 2012 10:01 pm
by bn
Hi Barry,
good morning.
Over here in Europe I will soon go to bed.
I thought we had changed the command handler
on SetPref ...
to a function
Function SetPref
actually we were talking about GetPrefs.
SetPrefs is a good example for a command (you don't want to get anything back, just set the values) whereas GetPrefs is a good case for a function (you want to get something back). Anyhow you can use either as long as the syntax is right.
have you looked at my latest post regarding saving the "myData" stack?
My remarks about quoting literals was less about execution speed, it happened to me that inadvertently I had used a variable name earlier on and later used the same name for a literal e.g. a field. Thats when things get tricky. But nevermind the quotes, you just have to be aware of a potential problem.
Kind regards
Bernd
Re: User Profile and User Properties DB?
Posted: Thu Feb 23, 2012 10:11 pm
by BarrySumpter
Thanks again for clarifying the differneces between command handlers and function routines.
Would the script we use to call these be referred to as command calls and function calls.
As in Call SetPref and Call GetPref?
Or would some other term be more clear?
Maybe, now some coffe n breakie and I should be right to go.
I find that I have more trouble with syntax errors when I use the "s cause I always forget one.
LOL
Sweet dreams confident in the fact that you have done at least one good deed for the day.
Re: dataStack - hide stack errors
Posted: Fri Feb 24, 2012 9:32 pm
by BarrySumpter
Code: Select all
on initPrefDB
set itemDel to slash -- start to build current path for stackData preferences
put the effective filename of this stack into realpath --gets current path
delete last item of realpath --removes .livecode file name on this stack
put realpath & "/Prefs.dat" into gPrefsDat -- adds SQLite file name to path
put "Preferences" into stkPreferneces
if not (there is a file gPrefsDat) then -- check to see if the preferences stack exists
create stack stkPreferneces -- doesn't exist - only now create the stack in memory
set the filename of stack stkPreferneces to gPrefsDat -- set the filename to folder and path
save stack gPrefsDat -- now save/ create the Preferences stack to disk
hide stack gPrefsDat
else
go stack gPrefsDat
hide stack gPrefsDat -- =======>>> errors with "can't find stack"
--save stack tFilePath
--hide stack tFilePath
--go this stack
end if
end initPrefDB
Re: User Profile and User Properties DB?
Posted: Fri Feb 24, 2012 9:50 pm
by bn
Hi Barry,
I guess you are pointing to the commentary in your script.
The error probably results from the fact that the name of the stack is "Preferences" as you put into your local variable stkPreferneces
Try:
or you could probably say
and skip the hide stack part.
Kind regards
Bernd
Re: User Profile and User Properties DB?
Posted: Fri Feb 24, 2012 10:26 pm
by BarrySumpter
Nice!
Go invisible ....
the dictionary even has the
go inivisible stack preferences
as a sample script.
Never would have figured that.
I think I should rename that gPrefsDat to gFldrLocPrefDat for a better description as well.
i.e. not a stk... stack object.
Many Thanks!