PoLyGLoT wrote:In general, I cannot seem to figure out a way to manipulate specific portions of information within an array. For instance, I tried something along the lines of "if item 5 of line x of tArray = blahblah, then blahblah" but that doesn't seem to work.
It may be the "blahblah" statement.

But seriously, posting your code is helpful for us to see exactly what's working and what isn't, so we can hone in on the best examples to make this gel for you.
As a general example, this illustrates how you can use chunk expressions on the contents of an array element:
Code: Select all
on mouseUp
put "Hello" into item 1 of tArray[1]
put "World" into item 2 of tArray[1]
put ",Big Wonderful" after item 1 of tArray[1]
put tArray[1]
end mouseUp
I'm confused about the language here: In an array, are "keys" the same things as "lines" in a standard variable? If keys = lines, what equals specific item numbers (e.g., if the "keys" in the array are comma delimited)?
Arrays aren't delimited string. Each has its own strengths and weaknesses, but they're quite different, which is why both are supported so well in the engine.
Arrays are key-value pairs, in which a value is stored into the array variable in a manner that's associated with the key.
You could think of an array as a collection of buckets, in which each bucket has a name (the key), and the contents of the bucket is the value.
The bucket is quite flexible: you can store any data, even binary data, up to about 4GB. The key is more limited: it can be no more than 255 characters, and cannot contain a NULL byte.
With delimited strings, you must access individual elements by number (line 1 or item 2).
With arrays, the key is a string, rather like a name, and you can use any alphanumeric string for that - the string may be numeric (tArray[1]) or not (tArray["Richard"]), but regardless of the characters used in the key's string it's still a string, just an arbitrary label used to address the bucket.
Numeric keys can be useful, such as a simple way to put things into buckets in a counting loop, e.g.:
Code: Select all
repeat with i = 1 to the number of fields
put the htmlText of fld 1 into tArray[i]
end repeat
But non-numeric keys are also useful, such as this rapid way to build a count of word frequencies:
Code: Select all
repeat for each word tWord in tString
add 1 to tConcordance[tWord]
end repeat
But regardless whether the key's string is numeric or alphanumeric, to the engine it's always just a string, some unique identifier to find the associated bucket.
One area where arrays can be especially helpful is in expressing data that may have more than two dimensions.
A delimited string can easily represent two-dimensional data, the sort of row-and-column stuff we think of with spreadsheets, using line and items. Useful as that is, sometimes you may need to go deeper.
For example, you may have a list of names with addresses and phone numbers. As a delimited list you'd have to use columns for each of those, so those who have more than one phone number would require multiple columns:
Code: Select all
Bob,123 Haight Street,555-1234
Jane,4444 Ambassador St,555-4444,555-3355
With arrays you could express that using multiple dimensions:
Code: Select all
put "123 Haight Street" into tArray["Bob"]["Address"]
put "555-1234" into tArray["Bob"]["Phone"]["Home"]
put "444 Amabassador St" into tArray["Jane"]["Address"]
put "555-4444" into tArray["Jane"]["Phone"]["Home"]
put "555-3355" into tArray["Jane"]["Phone"]["Mobile"]
This would give you a tree-like representation, which could be illustrated as:
Code: Select all
Bob:
Address: 123 Haight Street
Phone:
Home: 555-1234
Jane:
Address: 444 Ambassador St
Phone:
Home: 555-4444
Mobile: 555-3355
With array notation you don't have to use the literal value there (tArray["Bob"]) - you could use a variable as well. Here we count through the keys to extract a list of phone addresses:
Code: Select all
repeat for each key tKey in tArray
put tArray[tKey]["Address"] &cr after tAddressList
end repeat
This post has gotten too long so I'll stop here (I was tempted to get into a lengthy discussion of the speed differences between chunks and array accesses, but all of us have other things to do this morning <g>), but hopefully with these examples you can see ways you can use arrays to express your data.