The best way to store arrays as text file?

Jim Ault JimAultWins at yahoo.com
Wed Jan 10 18:24:52 EST 2007


On 1/10/07 11:00 AM, "Stephen Barncard" <stephenREVOLUTION at barncard.com>
wrote:

> Well I use two ways to store arrays...
> 
> Does the data need to be read outside of rev or not?
> If they're going to be read by a revolution app, then
> 
> they can be stored and recovered intact as a custom property set in
> an external stack.
> 
> I also pack them into a single custom property using tabbed fields
> for each record. One record on each line. First item is the key. If
> returns and other special characters are in the array then
> URLEncoding/Decoding can be used for certain data.

One handy, and very fast custom prop technique I use is ...
Start with the concept that a custom property set *is* an array.

on packCustomProps
   put the customproperties of this stack into tempArr
   combine tempArr using cr and tab --now tab delim
   put tempArr into url ("file:"& pathToFile & filename &".txt")
   --the current property set is now saved
end packCustomProps


--the reverse direction to use the data
on openstack
   put url ("file:"& pathToFile & filename &".txt") into tempArr
   split tempArr using cr and tab --now an array
   set the customproperties of this stack into tempArr
   --the current property set is now restored
end openstack
 --and the variable tempArr is purged by Rev when the handler ends

-----------------
> If text files are needed to move that data to anywhere else, you're
> probably limited to tab delimited fields with linefeeds subbed for
> returns in data and returns for records unless you use XML.
There are more options for storage if you consider Applescript for the Mac
or VBA for Windows, but that gets into exchanging data with companion apps
(which I do everyday), but definitely not simple.

Caution about text file storage.  Watch for the use of

put cr & newData after url ("file:"& pathToFile & filename &".txt")
--where over the weeks the file size can grow to over 2 Mb.  Performance
will slow dramatically, esp over 10 Mb.

Jim Ault
Las Vegas





More information about the use-livecode mailing list