Referencing cells by column and row name

Mark Brownell gizmotron at
Wed Dec 31 12:19:45 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?
> Appreciate any and all suggestions
> Mark Powell


You can use these three functions to pull-parse attributes from 
elements without regard to any XML parser restrictions. If this data 
information where embedded in HTML then the HTMLText would render this 
data as invisible or not there.

Save your data in field "states"as:

<Colorado population="10,000,000" area="400,000 sq mls"></Colorado>
<California population="50,000,000" area="999,000 sq mls"></California>
<North Dakota population="4,000,000" area="300,000 sq mls"></North 

Put all this into a button script:

on mouseUp
  put the text of field "states" into srchThis
  put getAttributeFromElement("Colorado", "population", srchThis) into 
  put getAttributeFromElement("North Dakota", "population", srchThis) 
into ndPop
end mouseUp

function getAttributeFromElement element, attribute, stringToSearch
   put "<" & element & " " into t1
   put "</" & element & ">" into t2
   put getElement(t1, t2, stringToSearch) into theElement
   put getAttribute(attribute, theElement) into theAttribute
   return theAttribute
end getAttributeFromElement

-- put getElement("<record>", "</record>", myString) into theElement
function getElement tStTag, tEdTag, stngToSch
   put empty into zapped
   put the number of chars in tStTag into dChars
   put offset(tStTag,stngToSch) into tNum1
   put offset(tEdTag,stngToSch) into tNum2
   if tNum1 < 1 then
     return "error"
     exit getElement
   end if
   if tNum2 < 1 then
     return "error"
     exit getElement
   end if
   put char (tNum1 + dChars) to (tNum2 - 1) of stngToSch into zapped
   return zapped
end getElement

-- put getAttribute("name", myString) into theAttribute
function getAttribute tAttribute, strngToSearch
   put empty into zapA
   put quote into Qx
   put tAttribute & "=" & Qx into tAttributeX
   put the number of chars in tAttributeX into dChars
   put offset(tAttributeX,strngToSearch) into tNum1
   if tNum1 < 1 then
     return "error"
     exit getAttribute
   end if
   put tNum1 + 1 into tNum2
   put offset(Qx,strngToSearch,tNum2) into tNum3
   put offset("=",strngToSearch,tNum2) into tNum4
   if tNum3 < 1 then
     return "error"
     exit getAttribute
   end if
   if tNum4 < tNum3 then
     return "error"
     exit getAttribute
   end if
   put char (tNum2 + 1) to (tNum3 - 1) of stngToSch into zapA
   return zapA
end getAttribute

Mark Brownell

More information about the use-livecode mailing list