Arrays

Bernard Devlin bdrunrev at gmail.com
Wed May 20 06:15:35 EDT 2009


Hi Tom,

Assuming your data is in a variable called tData, and is structured like this:

Elliot and Cooper Roads, sparrow
Elliot and Cooper Roads, magpie
Elliot and Cooper Roads, dove
Elliot and Cooper Roads, owl
Downing Street, sparrow

this will give you a list of the birds in Elliot and Cooper Roads:

put tData into tSubset
put "Elliot and Cooper Roads" into tRoadName
filter tSubset with (tRoadName & "*")
replace (tRoadName & comma & space) with empty in tSubset

tSubset now contains a list of bird types from tRoadName.

If you want to extract each road name and get the list of birds seen
at that place, then you will need to loop over the whole list to
associate all the birds from a place with just that name.

It would probably be easier to be using an array for this.  In case
you are having trouble imagining it as an array, I generally think of
arrays in Rev as dictionaries.  That is, each identifier in the array
is unique like the head words in the dictionary, and each has data
associated with it.

If you used an array (a dictionary) then each road name would be like
a word you look up in the dictionary.  When you wanted to add an
observation made at a particular road it would be as easy as this:

put "sparrow" & return after tObservationDictionary[tRoadName]

To get all the birds for 1 road you would do this:

put tObservationDictionary[tRoadName] into tBirdList

To get a list of all the roads, it would be:

put the keys of tObservationDictionary

Hope that helps.

Bernard



More information about the use-livecode mailing list