newbie question about finding elements in table fields

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gernhuijberts
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2
Joined: Sun Oct 31, 2010 11:24 pm

newbie question about finding elements in table fields

Post by gernhuijberts » Sat Nov 06, 2010 5:19 pm

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!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: newbie question about finding elements in table fields

Post by bn » Sat Nov 06, 2010 7:02 pm

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
Attachments
dataItems for gernhuijberts.livecode.zip
(1.79 KiB) Downloaded 200 times

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: newbie question about finding elements in table fields

Post by bangkok » Sat Nov 06, 2010 7:34 pm

Other solution with ITEMOFFSET
Attachments
ITEMOFFSET.zip
(953 Bytes) Downloaded 191 times

gernhuijberts
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2
Joined: Sun Oct 31, 2010 11:24 pm

Re: newbie question about finding elements in table fields

Post by gernhuijberts » Sat Nov 06, 2010 8:32 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: newbie question about finding elements in table fields

Post by bn » Sat Nov 06, 2010 9:11 pm

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

Post Reply