Referencing cells by column and row name

Dar Scott dsc at swcp.com
Tue Dec 30 21:23:07 CST 2003


On Wednesday, December 31, 2003, at 02:17 AM, Mark Powell wrote:

> Say I have 50 lines of tab-delimited data.  Each line represents one 
> of the 50 U.S. states.  Each item within a line corresponds to some 
> kind of data (population, area, etc.)  Is there any way using Rev's 
> built-in commands to write something akin to
>
> get item "Population" of line "Colorado"
>
> where Population and Colorado are not variables, but 'column' and 
> 'row' names.  Is it possible to establish names in this way and 
> retrieve data similarly to above?

(I'm assuming the item delimiter is adjusted appropriately for item 
chunks.)

1.
Make Population and Colorado constants, or, if this must work among 
many scripts, globals set in initialization.

    get item Population of line Colorado of currentData

2.
Set up global arrays in initialization.

    get item data["Population"] of line state["Colorado"] of currentData

3.
Use functions.  The state function returns a line.  The datum function 
returns an item from a line.  The data is in a global.  Can't be used 
to change the value.

    get datum("Population", state("Colorado") )

4.
Use a function for each datum or state.  Colorado() returns the 
colorado line.  Population() returns the Pop item.  The data is in a 
global.  Can't be used to change the value.

    get Population( Colorado() )

5.
Switch to arrays.  The data array is in a global named data.

    get data["Population","Colorado"]

6.
Make an interpreter.  Replace item key words like "Population" with 
"item 4" and line key words like "Colorado" with "line 7 of stateData". 
  Then "do".

    MarkDo "get Population of Colorado"

That's enough to get you thinking, I hope.

Dar Scott






More information about the use-livecode mailing list