Correct use of function "selectedline"

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
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Correct use of function "selectedline"

Post by Simon Knight » Sun Dec 08, 2013 11:14 am

Hi,

The function selectedline returns a text description in the form "line 4 of field 3". I have attempted and failed to use this directly to extract some text stored in a field e.g. put item 2 of the selectedline of me into myVariable. I have tried various permutations and locations for the code without success. In the end I resorted to the following code which is attached to a field object:

Code: Select all

on mouseUp 
     put the selectedline of me into tLine  -- user clicks on a line in the field
   answer  "tLine is set to : " & tLine  // "line 4 of field 3"
   
   put word 2 of tLine into tLineNo  // 4
   answer "tLineNo is " & tLineNo
   
   set itemdelimiter to tab
   put item 2 of line tLineNo of me into tFileName
   answer "File Name: " & tFileName  // correctly returns the second item
   
End Mouseup
This code works but it seems clumsy, as the text the function returns, "line n of field x", seems designed to be used directly. Please will someone confirm how it should be used?

thanks
best wishes
Skids

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Correct use of function "selectedline"

Post by Klaus » Sun Dec 08, 2013 4:58 pm

Hi Simon,

is this a listfield?
if yes, you can have it shorter with:
...
set itemdel to TAB
answer "Filename:" && item 2 of the selectedtext of me
...

Best

Klaus

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Re: Correct use of function "selectedline"

Post by splash21 » Sun Dec 08, 2013 5:02 pm

You can also try;

put item 2 of the value of the selectedLine.....
LiveCode Development & Training : http://splash21.com

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

Re: Correct use of function "selectedline"

Post by dunbarx » Sun Dec 08, 2013 5:06 pm

Hi.

May I assume that your field text already is delimited by tabs? And that the field is a locked list field? Would this do:

Code: Select all

on mouseUp
   set the itemDel to tab
   answer item 2 of the value of the clickLine
end mouseUp
Craig Newman

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Correct use of function "selectedline"

Post by Simon Knight » Sun Dec 08, 2013 6:11 pm

Thanks for the code: the line

Code: Select all

set itemdel to TAB
answer "Filename:" && item 2 of the selectedtext of me
did not work, but the lines that use "the value" do.
best wishes
Skids

Post Reply