Display entire line in another field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Display entire line in another field

Post by urbaud » Wed Feb 23, 2011 1:24 am

Hi,
I have a field with about 40 lines in it. Each line begins with a date and is followed by some text, eg. "jan 15 george's birthday". I am using the Find command to find a particular date, which works great. However, I would like to then display the found LINE in another field. So, when I find a particular date, I would like the program to automatically "grab" the entire line and display it in another field. Can anyone help me in understanding how to do this? Thanks.
urbaud

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Display entire line in another field

Post by Dixie » Wed Feb 23, 2011 2:45 am

urbaud...

Code: Select all

on mouseUp
   put "Jan 1" into theDateToFind
   
   find whole theDateToFind in fld 1
   put line (word 2 of the foundLine) of fld 1 into fld 2
end mouseUp
That should help you... see the 'foundLine', the 'clickLine' in the dictionary.

take care

Dixie

urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Re: Display entire line in another field

Post by urbaud » Wed Feb 23, 2011 8:44 am

Hi Dixie,
Thank you so much for the help. It works like a charm and it's exactly what I wanted. I added the 'Ask' command so I can search for any one of the 40 or so lines. I knew the code would be rather short, but I just didn't have a clue about how to tackle the issue. So, again, thanks for the help.
Dan
urbaud

monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Re: Display entire line in another field

Post by monki » Tue Dec 13, 2011 11:05 pm

put line (word 2 of the foundLine) of fld 1 into fld 2
I had a similar problem and this solution worked for me as well, but I wonder why. What does adding the code (word 2 of the foundLine) do, and why does this return the whole line of text and not just the second word? Sorry for the stupid questions, but this is all new to me.

Thanks for help

m.

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

Re: Display entire line in another field

Post by dunbarx » Wed Dec 14, 2011 12:48 am

Hi.

Read the code again. It states: "line (word 2 of the foundline) of fld 1.

Break this down and you can see it says: "line (2) of fld 1 -- the "foundline" returns "line x of field y" --the "2" is arbitrary.

Check out the dictionary.

This is one of the beautiful things about LC, that statements are resolved before they are executed. This takes just a little getting used to, but once mastered with just a bit of experimentation, becomes incredibly powerful and fun to use.

Craig Newman

monki
Posts: 59
Joined: Tue Dec 13, 2011 10:56 pm

Re: Display entire line in another field

Post by monki » Wed Dec 14, 2011 1:46 am

dunbarx wrote:Read the code again. It states: "line (word 2 of the foundline) of fld 1.
Break this down and you can see it says: "line (2) of fld 1 -- the "foundline" returns "line x of field y" --the "2" is arbitrary.
I understand that it's returning the line number of the selection. I originally used something like -- put line foundline of field x into field y. This would return not the selected text, but a reference to the line of the selected text: "line 42 of field 1". So does the use of "word 2" in the code force LiveCode to return the text rather than the reference to the text? Could I have used "word 3" or "word 5" and have it work as well? Why doesn't the use of "word 2" limit the text returned to only the second word of that line?

Oh. I was thinking of foundLine as a variable name, not a function. So word 2 of foundLine's returned chunk is the "lineNumber", and that explains why it works.
Thanks

Post Reply