Arrays and custom properties
Jan Schenkel
janschenkel at yahoo.com
Mon Aug 4 21:12:01 EDT 2003
--- Bill Vlahos <bvlahos at mac.com> wrote:
> I am struggling with the concept of arrays and
> custom properties and am
> looking for a cookbook example.
>
> Let's say I want to make something like the included
> Employee Database
> example that comes with Rev. It makes a new card for
> each record but I
> don't want to do that, I want to put the information
> in an array and
> store it in a custom property. This will allow me to
> have complex
> information in a field such as TABS, RETURNS, and
> maybe formatting in a
> field (like a notes field) and encrypt the data by
> password protecting
> the stack.
>
> My problem is that I don't know how to actually code
> it. Here is a
> simple scenario:
> 1. Stack named "Company Directory" as a standalone
> 2. Stack named "CDData.rev" where the data will be
> stored in a custom
> property
> 3. Card named "Employees" with 4 fields
> FirstName
> LastName
> Notes
> Index (to show all of the records in a list field.
> Click on the item
> to populate the other fields.)
>
> All of the data will be in an array which is read
> from or written to
> the custom property.
> 1. The array is modified when records are added,
> deleted, or changed.
> 2. The array is saved to the CDData.rev stack in a
> custom property when
> the item is changed.
> 3. Upon opening the standalone, data is read from
> the custom property
> which is then put into the Index field.
>
> How would I do this? I think it is likely to be
> simple but I am unclear
> on the execution.
>
> Thanks in advance. I'll submit the finished stack to
> RunRev as a user
> contribution.
>
> Bill Vlahos
>
Hi Bill,
When using custom properties to store data in a stack,
I usually follow this strategy :
- 1 table = 1 custom property set
- each record is broken up into its fields
- 1 field = 1 custom property within the above set
- the key of the custom property is composed of the
primary key and the field name
When I need to store data, I can easily
put fld "customerID" into tCustID
set the uCustomerData[tCustID,"name"] of this card \
to fld "customerName"
set the uCustomerData[tCustID,"city"] of this card \
to fld "customerCity"
So my custom property set ends up looking like :
uCustomerData[1,name] = "John Doe"
uCustomerData[1,address] = "unknown"
uCustomerData[1,city] = ""
uCustomerData[1,zipcode] = ""
uCustomerData[1,state] = ""
uCustomerData[2,name] = "Christopher Robinson"
uCustomerData[2,address] = "Fifth Avenue"
uCustomerData[2,city] = "New York"
uCustomerData[2,zipcode] = "12345"
uCustomerData[2,state] = "NY"
When I need to retrieve data, I can easily
get the uCustomerData[tCustID,"name"] of this card
One trick that might come in handy :
put the customKeys["uCustomerData"] into tCDataKeys
filter tCDataKeys with "*,name"
Now item 1 of each line of tCDataKeys is a customer
ID, and you can easily fill up a list field for the
user to select a customer.
Hope this helped,
Jan Schenkel.
=====
"As we grow older, we grow both wiser and more foolish at the same time." (La Rochefoucauld)
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
More information about the use-livecode
mailing list