Finding the actual position of a clicked word

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
Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Finding the actual position of a clicked word

Post by Fermin » Thu Feb 01, 2018 1:40 pm

Please, I need some help.

Is there any direct way to find out the position of a particular word that is repeated several times in a string without using the ...ToSkip option?

wordOffset always provides the first one it finds.

e. g.
There is a line with 5 words in the field elCampo: Helen Paul Robert Paul Doris
If I click on the second Paul (the fourth word)... how do I know that I clicked on that second Paul and not the first Paul?
--
put line 1 of field elCampo into verso
put the clickText into palabra
put wordOffset (palabra, verso) into ofe

result: ofe = 2
and i need: ofe = 4
--
Thank you very much.

(Translated with www.DeepL.com/Translator)

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Finding the actual position of a clicked word

Post by Klaus » Thu Feb 01, 2018 2:15 pm

Hola fermin,
...without using the ...ToSkip option?
no way, sorry, you will always need a repeat loop and the SKIP parameter.

But in your case here it looks like you need to check something like e.g. "the clickchunk".


Best

Klaus

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Finding the actual position of a clicked word

Post by Fermin » Thu Feb 01, 2018 4:55 pm

That's great, Klaus. I was already using clickchunck as a visual reference (select the clickchunk) but you gave me a great idea because it also serves my purpose: to use a field to show and modify values
(200 0.57 95000 -25.60 etc...).

There is only one small problem: I have checked that 'the clickchunck' does not pick up the minus sign (-) in negative values but I will solve it with a little more code.

Thank you very much, Klaus. :)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Finding the actual position of a clicked word

Post by jacque » Thu Feb 01, 2018 7:38 pm

This might work:

Code: Select all

put char 4 of the clickchunk into tChar
put the number of words in char 1 to tChar of the clickLine 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Finding the actual position of a clicked word

Post by jmburnod » Thu Feb 01, 2018 7:57 pm

I think Jacqueline means "word 4 of the clickchunk" instead "char 4 of the clickchunk"

This seems work

Code: Select all

   put word 4 of the clickchunk into tChar
   put the number of words in char 1 to tChar of fld 1 into h
   put word h of fld 1  
Best regards
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Finding the actual position of a clicked word

Post by jacque » Thu Feb 01, 2018 8:18 pm

jmburnod wrote:
Thu Feb 01, 2018 7:57 pm
I think Jacqueline means "word 4 of the clickchunk" instead "char 4 of the clickchunk"
You're absolutely right. I should stop typing on my tablet. :)

Thanks for catching that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: Finding the actual position of a clicked word

Post by Fermin » Fri Feb 02, 2018 12:46 am

Very good idea too, Jacqueline. It will be very useful in the future.

My purpose is to modify values that I have in a table similar to this one:

1 <heading> 1 29 -10 -190 ABS
0 <tilt> 35 39 -50 50 REL
0 <altitude> 1 18 50 -150 REL
1 <range> 1 100 76 -14 REL

Process:
Capture by clicking on a numeric value > modify > return new value to original position

The small inconvenience is to capture the negative values because I can't find a function that detects the minus sign... mouseText or clickText don't do it. Is there any function that will do it?

If not, I think the best solution is to check the previous character to the one offered by the word 2 of the clickchunk and process the result.

Thank you, Jacqueline and Jean-Marc

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Finding the actual position of a clicked word

Post by dunbarx » Fri Feb 02, 2018 1:33 am

Hi.

I regularly use a function, written in HC decades ago, that lists all instances of a string in a body of text, and where they occur. This is little different than the suggestions you already have. But that sort of thing, along with a little finagling, should be fun to write and useful in the future.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Finding the actual position of a clicked word

Post by dunbarx » Fri Feb 02, 2018 5:35 am

Just so everyone knows, that adorable method of finding (pseudo):

Code: Select all

 the number of chunks from the beginning to the click|selected|whatever chunk...
to see how far along one is to a point of interest in a body of text was, I believe, invented by Jacque about 25 years ago in Hypertalk.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Finding the actual position of a clicked word

Post by [-hh] » Fri Feb 02, 2018 2:16 pm

Yet another option:

Use links (and get also the minus sign).

Code: Select all

repeat with i=1 to the num of lines of fld 1
    repeat with j=1 to the num of words of line i of fld 1
       set textstyle of word j of line i of fld 1 to "link"
    end repeat
end repeat
Now you can use by clicking on the locked field "the clickchunk" and "on linkClicked" for your action (don't forget to set again the textstyle for the replaced chunk).
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Finding the actual position of a clicked word

Post by dunbarx » Fri Feb 02, 2018 3:31 pm

Hermann.

Not sure I get your idea. All words are now links, and a click in the field simply returns the clickChunk.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Finding the actual position of a clicked word

Post by [-hh] » Fri Feb 02, 2018 4:18 pm

Hi Craig,

if the textstyle is "link" then the clickchunk returns the *linked* chunk (some say "grouped" chunk), and "on linkClicked w" returns in w the linkText. All he needs (incl. the minus sign).

Code: Select all

on linkclicked w
  put w &": "& the clickchunk -- exact info about the 'link-click'.
end linkclicked
The following, for example, increases/decreases each clicked number by 1 if clicked with shiftkey down/up.

Code: Select all

on linkclicked w
  put the clickchunk into c
  put word 2 of c into c0
  put w &": "& c into fld 2
  if w is a number then
    if the shiftkey is up then put w-1 into x
    else put w+1 into x
  else put upper(w) into x
  put c0+len(x)-1 into c1 -- minus sign may switch on/off
  do "put x into " & c
  set textstyle of char c0 to c1 of fld 1 to "link"
end linkclicked
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Finding the actual position of a clicked word

Post by dunbarx » Sat Feb 03, 2018 12:49 am

Ah, I see. OK.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”