Page 1 of 1

Correct use of function "selectedline"

Posted: Sun Dec 08, 2013 11:14 am
by Simon Knight
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

Re: Correct use of function "selectedline"

Posted: Sun Dec 08, 2013 4:58 pm
by Klaus
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

Re: Correct use of function "selectedline"

Posted: Sun Dec 08, 2013 5:02 pm
by splash21
You can also try;

put item 2 of the value of the selectedLine.....

Re: Correct use of function "selectedline"

Posted: Sun Dec 08, 2013 5:06 pm
by dunbarx
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

Re: Correct use of function "selectedline"

Posted: Sun Dec 08, 2013 6:11 pm
by Simon Knight
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.