Array, Array, who has got the array?

Mark Brownell gizmotron at earthlink.net
Sun Feb 29 11:26:34 EST 2004


On Saturday, February 28, 2004, at 08:16  PM, Mark MacKenzie wrote:

> Good evening (or morning).  My current project could probably stand to 
> have at least one array in it to handle complicated groupings of data. 
>  However, I have never used one or created one before.
>
> I looked at the excellent Frogsbreath.rev project but quite frankly 
> couldn't undrestand the actual workings and how they might apply to my 
> work.

It's 7:00 AM on the west coast of the USA and I'm watching Tiger Woods 
play golf... go figure

That frogBreath.rev project was mine. I needed a device that could 
store pages of text in individual containers. I wanted to be able to 
let the user change the order of the pages, like for example moving 
page 30 to page location 38 and automatically correcting the order of 
the rest of the pages. I wanted to add new pages to the end or 
somewhere in between. I wanted to delete pages. In order to do this 
with an array I had to come up with a naming convention that used 
numbers for keys.

In an array you associate the data you wish to recall with a key to 
recall it with. When I created the array manipulation example I assumed 
the use of sequential numbers starting at 1 for the first key. So if I 
wanted to store some text I would just put my text into an array at key 
"1." Later I can get my needed text by asking for the text that is 
stored at key "1."

It looks like this:

put "What does Blowfish and frogBreath have in common?" into myArray[1]
put the text of field "pages" into myArray[2]

To get data out of the array you need to ask for it using the 
associated key. That looks like this:

put myArray[1] into zap
put myArray[2] into zapPage2

-- I use zap for a var because that is the feeling & sound of electrons 
crackling

You can use numbers of characters as keys to store data in your arrays. 
You can use keys like "theDate", "theDay", "theMonth", "theAddress1", 
thePhoneNumber", etc...

You could use functions to create keys like:
put date() into zap
put "I have an appointment today at 3:00" into myArray[zap]

Later you can call the data by asking for it by the date/key.
put myArray[02/29/04] into whatDoIHavetoDoToday

Note: in some instances you might need to use quotes with your keys:
like: put myArray["02/29/04"] into whatDoIHavetoDoToday

Hope this helps,

Mark



More information about the use-livecode mailing list