I want to take an good old-fashioned tab-separated set of values with returns at the end of each line, like the following table:
#########################################
# Type # a # b # c #
#########################################
# fruit # apple # banana # cherry #
#########################################
# veggie # avocado # bean # corn #
#########################################
# person # Andy # Barb # Charlie #
#########################################
I want to put it into tArray, and then split the tArray such that I get:
tArray["fruit"]["a"] = apple
tArray["person"]["c"] = Charly
etc.
It would seem like the split command is made to do exactly this. This is what I have:
Code: Select all
on mouseUp
set the text of field "Table" to empty
# creates the data just so I know I'm not crazy
put "Type" & tab & "a" & tab & "b" & tab & "c" & return into field "Table"
put "fruit" & tab & "apple" & tab & "banana" & tab & "cherry" & return after field "Table"
put "veggie" & tab & "avocado" & tab & "bean" & tab & "corn" & return after field "Table"
put "person" & tab & "Andy" & tab & "Barb" & tab & "Charly" after field "Table"
# the action begins here
put the text of field "Table" into tArray # puts it into variable. This works as expected, one record per line, tabs between.
split tArray with return and tab # <-- This seems like it should do what I want. But I get a blank tArray array.
end mouseUp
Code: Select all
set the columnDelimiter to tab
set the rowDelimiter to return
split tArray with row and column
Code: Select all
split tArray with return
tArray[1] = Type a b c
tArray[2] = fruit apple banana cherry
tArray[3] = veggie avocado bean corn
tArray[4] = person Andy Barb Charly
I suppose I could iterate through each tArray[n] but according to the dictionary this should work, and I presume split would be much faster than me doing that.
It seems like this should be simple, but I've been pounding my head against it.
Thanks for any insights. (If it matters, am in Windows environment, using version 9-6-7.
GLS