array info request
Mark Wieder
mwieder at ahsoftware.net
Mon Jul 25 18:13:24 EDT 2005
keith-
Monday, July 25, 2005, 1:15:38 PM, you wrote:
k> Ermm... :-)
k> Okay, in my state of blissful ignorance I had assumed that arrays
k> were effectively arranged in a spreadsheet-like manner. The array
k> name is the spreadsheet (in this way of thinking), the keys are like
k> a set of column headings, and the elements are the bits of data in
k> each cell. I hope I'm not too off-target here! <g>
k> Anyway, an example of data in this layout, assuming it isn't just bonkers:
k> Record Title ISBN Author Editor Comments
k> 1 ABC 123 Tim Tom Lots of blahblah...
k> 2 House 345 Mick Mark Different blahblah...
k> Can I extract every record number and title in order to search for
k> just titles? (I'm imagining that I'd need to know which record ID a
k> found item was in to be able to pull the full record.)
Here's an example of one way to do this - there are other ways as
well. Do you actually need a Record number, or is just a holdover from
spreadsheet-thinking? Here I'm using the ISBN as the index, assuming
that it's unique for each record. (untested)
local tISBN, tKeys, tBooks
-- do something like this for each record
put 123 into tISBN
put "ABC" into tBooks[tISBN,"title"]
put "Tim" into tBooks[tISBN,"author"]
put "Tom" into tBooks[tISBN,"editor"]
put "Lots of blahblah" into tBooks[tISBN,"comments"]
-- now to find a title in the array:
-- the title to search for is in strSearchString
put empty into tFoundTitle
put the keys of tBooks into tKeys
-- now you have a list of the array indices
-- you're only interested in titles right now
filter tKeys with "*title"
repeat for each line tLine in tKeys
if strSearchString is in tBooks[tLine] then
-- item 1 of the index is the ISBN
put item 1 of tLine into tFoundTitle
exit repeat
end if
end repeat
-- now tFoundTitle contains the found ISBN or is empty.
k> The rough idea in my head right now is to store the data in an array
k> in a project:
You're bordering *very* close to where you'd be better off using a
database than trying to store things in arrays.
Keep in mind that arrays are temporary. If you need persistent storage
and you're not using a database then you'll need to store the arrays
in custom variables in a substack:
set the books of mySubStack to tBooks
--
-Mark Wieder
mwieder at ahsoftware.net
More information about the use-livecode
mailing list