Page 1 of 1
Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 1:40 pm
by Fermin
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)
Re: Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 2:15 pm
by Klaus
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
Re: Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 4:55 pm
by Fermin
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.

Re: Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 7:38 pm
by jacque
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
Re: Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 7:57 pm
by jmburnod
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
Re: Finding the actual position of a clicked word
Posted: Thu Feb 01, 2018 8:18 pm
by jacque
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.
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 12:46 am
by Fermin
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
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 1:33 am
by dunbarx
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
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 5:35 am
by dunbarx
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
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 2:16 pm
by [-hh]
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).
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 3:31 pm
by dunbarx
Hermann.
Not sure I get your idea. All words are now links, and a click in the field simply returns the clickChunk.
Craig
Re: Finding the actual position of a clicked word
Posted: Fri Feb 02, 2018 4:18 pm
by [-hh]
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
Re: Finding the actual position of a clicked word
Posted: Sat Feb 03, 2018 12:49 am
by dunbarx
Ah, I see. OK.