Arrays for lists with multiple lines where item 1 is the same on N number of lines

Kay C Lan lan.kc.macmail at gmail.com
Fri Apr 22 03:39:49 EDT 2016


This might get you started with your first problem of how to avoid
overwriting data.

Assuming your second long list is tab separated and been read into a
variable tManyRecords

set the itemDel to tab
repeat for each line tRecord in tManyRecords
  put item 1 of tRecord into tParent
  put item 2 of tRecord into tChild
  if (aArray[tParent] = empty)  then
    put tChild into aArray[tParent]
  else
  --add another child
    put aArray[tParent] & comma & tChild into aArray[tParent]
  end if
end repeat
put aArray[138] into msg -- 43,131,6 should appear in the msg box

--be careful about choosing a list delimiter
--comma is a BAD choice unless you KNOW it's ALWAYS going to be a number
--but even then someone's going to come along with 5,678 and use a comma as
a thousand separator

It's really just a matter of testing whether the Array Key is empty or not.

HTH



More information about the use-livecode mailing list