Arrays and Custom Props
JimAultWins at yahoo.com
Fri Feb 13 17:53:23 CST 2009
Just a couple hints that might help you in the future.. I hope this can
help someone understand a little more.
I think of arrays as..
Arrays, like variables, evaporate on quitting,
Custom properties, like button names, are stored in the stack file.
(note: this is not true for compiled apps since they cannot be modified
You store data in custom properties before compiling and they become part of
your app, such as jpgs, sounds, even whole stack files)
*split a block of lines into compartments as keys and values
*split a list into keys and values
--caution: duplicate list lines will become (one) key:value pair since keys
by definition must be unique and thus data loss.
*combine keys and elements into one block of text (eg. a list of lines)
a custompropertyset *is* an array
a custom property is one key:value pair in a custompropertyset
-- viewing a property set in the message box
put the custompropertyset "JimsColorFormats" of this stack into thisArray
combine thisArray using cr and tab
put thisArray into msg
Oh, and the syntax is the opposite....
set the properties to values
...just like 'set the name of btn 1 to "open me"
...just like 'set the rect of btn 1 to "23,45,65,109"
...just like 'set the "dataStore" of btn 1 to "value to keep"
put the values into an array
...just like 'put "fire truck" into tVehicleName --var
...just like 'put "Blue" into Julie["eyes"] --array
...just like 'set the "hair" of btn "Robert" to "brown" --object
...just like 'put "Brown" into Robert["hair"] --array
save this stack only saves the object
If you do a lot of property set manipulation, you might want to use this
trick to make it easier to debug using variable watcher:
(custom properties are harder to see when stepping through your handlers, so
do this to make it faster for you)
put the custompropertyset "storedAccountBalances"
of this card into acctBalArray -- an array to use for now
put totalToday into accBalArray[the short date]
put accBalArray["1/2/09"] into dailyTotal
put 0 into accBalArray[the short date]
put the short date into thisDay
add 1 to accBalArray[thisDay] --no quotes!please
add 24.95 to item 1 of accBalArray[thisDay]
put "as of 11:30 am" into item 2 of accBalArray[thisDay]
add 10.50 to item 1 of accBalArray[thisDay]
put "as of 11:45 am" into item 2 of accBalArray[thisDay]
--at end of day
repeat for each key KEYSTRING in accBalArray
put " as of 5:00 PM" into word 2 to -1 of accBalArray[ KEYSTRING ]
--again, no quotes around KEYSTRING
--- convert to a list
get accBalArray[the short date]
combine it using cr and tab
put it into the message box
set the custompropertyset " storedAccountBalances"
of card ""DailyData" of this stack to accBalArray
set the cpsLogInfo[the short date]
of card "Acctg Log Info" of this stack to
save this stack
Report of a custom property set is easy.
Get a property set, combine to make it a simple variable
Then use it as you wish, like this:
put the custompropertyset "cpsLogInfo"
of card "AcctgLogInfo" of this stack into tempp
-- 'tempp' is now an array, as you can see in variable watcher
combine tempp using cr and tab -- is now a list
put tempp into msg
set the cpsReportStorage["February2009"]
of card "AccountingReports" to tempp --(a simple variable)
save this stack
If you want to add more data to a custom property set as a series of numbers
(keep incrementing the keys by 1) use this
(assuming all the keys are numbers)
put the keys of custompropertyset "purchaseOrders" into tempp
replace cr with comma in tempp
put max(tempp) +1 into newKeyString
set the purchaseOrders[newKeyString] of this stack
to "132.89, Office Supplies"
Yes, a little light reading for the weekend, but this might help someone get
a handle on these concepts.
And now back to my client's app deadline :-)
On 2/13/09 12:41 PM, "Bernard Devlin" <bdrunrev at gmail.com> wrote:
> Don't feel too bad. So the dictionary does contain an example for what you
> needed, but after 6 years of using Revolution I still have to look up how do
> work with custompropertysets & arrays almost every time I use them together!
> Not to mention that I can never remember which way round 'split' &
> 'combine' work.
> I think I must have been particularly stupid at the time when I was learning
> how to use arrays, and my confusion has been permanently wired into my brain
> On Fri, Feb 13, 2009 at 7:31 PM, Gregory Lypny
> <gregory.lypny at videotron.ca>wrote:
>> First example: "...myPropertiesArray". Boy, do I feel dumb.
>> Thank you, Thierry.
>> On Fri, Feb 13, 2009, at 1:00 PM, use-revolution-request at lists.runrev.com
>> Le 13 févr. 09 à 17:55, Gregory Lypny a écrit :
>>> Hello Everyone,
>>>> If I'm not mistaken, I recall reading something a while back that
>>>> an array can now be a custom prop and that there was an easy way to
>>>> get a listing of all your custom props. I can't seem to find it.
>>>> If anyone can point me in the right direction, I'd much appreciate it.
>>> may be you could look at customProperties in the Dictionnary ?
>>> Seems it is what you need...
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
More information about the use-livecode