Page 1 of 1

newbie question about finding elements in table fields

Posted: Sat Nov 06, 2010 5:19 pm
by gernhuijberts
Hello,

I'm struggling with the following problem, days of searching the internet and livecode fora haven't brought me any closer to a solution.

I want to select a line a table field by finding a matching name and the store a number of associated parameters in variables.
The table field contains the name in the first column, the number of parameters in the second column and the actual parameters in the rest of the columns.
Sounds rather uncomplicated but I really haven't got a clue how to do it.
Any help is greatly appreciated!

Re: newbie question about finding elements in table fields

Posted: Sat Nov 06, 2010 7:02 pm
by bn
Hi Gern,

welcome to the forum.

a table field has the format of Lines = return delimited and on a line the items of the table are tab delimited.

suppose you have a tablefield in field 1. Your first column = the text before the first tab has the name of the line.
abd 2 15 29
def 3 11 30 23
ghi 4 42 44 46 48
jkl 3 18 19 20
lets suppose that the names of the rows of the tablefield = item 1 of a line are unique.
you have a second field, make a button, set the script of the button to:

Code: Select all

on mouseUp
   put field 1 into tData
   set the itemDelimiter to tab
   repeat with i = 1 to the number of lines of tData
      if item 1 of line i of tData is "ghi" then 
         put line i of tData into tFoundLine
         exit repeat
      end if
   end repeat
   put tFoundLine into field 2
end mouseUp
this puts line 3 into field 2
ghi 4 42 44 46 48
the variable tFoundline contains row 3. Important is the fact that you have to set the itemdelimiter to tab. The default itemdelimiter is comma.
for the rest you would have to explain a little your data structure. Do you know in advance what the columns are? Do you have the variables ready to take up data. Do you have to create the variables on the fly (confusing and difficult).
I would store the master index = column 2 in a variable and the rest of the actual values in another variable


. Leave them in the tab delimited format and you can always access them as item x of myActualValuesVariable
Dont forget that the itemdelimiter has to be set to tab in that case.

I attached my teststack. This might make things clearer.

I hope this gets you started.

regards
Bernd

Re: newbie question about finding elements in table fields

Posted: Sat Nov 06, 2010 7:34 pm
by bangkok
Other solution with ITEMOFFSET

Re: newbie question about finding elements in table fields

Posted: Sat Nov 06, 2010 8:32 pm
by gernhuijberts
Thank you Bernd,

That makes it a lot clearer, I was actually looking for functions or commands that would do the trick but this is very straight forward!
Thank you again
Gern

Re: newbie question about finding elements in table fields

Posted: Sat Nov 06, 2010 9:11 pm
by bn
Gern,

you are welcome. If you have questions please don't hesitate to ask here in the forum.

bangkok's solution is an advanced concept. I tried to keep it simple so you get the basics of chunk operations in Livecode.

Chunks in Livecode are very powerful and fun to use once you get the idea behind it.

regards

Bernd