Pulling a row from a table

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
Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Pulling a row from a table

Post by Thalor » Wed May 13, 2015 8:37 pm

If I wanted to set the text of a Label field to something that is in a basic table how would I do it?

My table (TextTable) is set up as such (tab delimited)

1 Choice1
2 Choice2
3 Choice3
4 Choice4
5 Choice5


If I wanted JUST key # 4 (Choice4) how would I query the table by the key to pull the "text" part that I wanted to set the label field (labeltext) to?

Thanks in advance.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Pulling a row from a table

Post by dunbarx » Wed May 13, 2015 9:16 pm

Hi.

The trick is to parse your data. You surely already know instinctively that to get the line of interest, you would:

Code: Select all

answer line 4 of fld "yourTableField"
But to get just the second part of line 4, you need to parse at the line level. Is your data separated by spaces? That is, are there two words in that line? If so:

Code: Select all

answer word 2 of line 4 of fld "yourTableField"
If the two parts are separated (delimited) by a tab character, as you say, you would have to go to the dictionary and look up the "itemDelimiter", play around with the examples there, and write back with the two-liner that will do what you want to.

Craig Newman

Thalor
Posts: 6
Joined: Thu Feb 12, 2015 4:35 pm

Re: Pulling a row from a table

Post by Thalor » Fri May 15, 2015 4:58 pm

Ok so if I wanted to get column 3 row 3 of a table

set itemdelimter to tab
put column 3 of line 3 of field "TextTable" into field "DialogText"

Would that work? Or something similar? I'm very new to this.

thanks in advance.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Pulling a row from a table

Post by dunbarx » Fri May 15, 2015 5:11 pm

Hi.

Your thinking is correct, but not your syntax. When you set the itemDelimiter, you are talking about items, a class of chunk similar to lines, words, and characters. Each of these is delimited by specific characters, for example, lines are delimited by returns.

You would:

put item 3 of line 3 of field "TextTable" into field "DialogText"

So you need practice, which is normal.

Craig

Post Reply