Finding the actual position of a clicked word
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Finding the actual position of a clicked word
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)
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
Hola fermin,
But in your case here it looks like you need to check something like e.g. "the clickchunk".
Best
Klaus
no way, sorry, you will always need a repeat loop and the SKIP parameter....without using the ...ToSkip option?
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
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.
(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.
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Finding the actual position of a clicked word
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
HyperActive Software | http://www.hyperactivesw.com
-
- 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
I think Jacqueline means "word 4 of the clickchunk" instead "char 4 of the clickchunk"
This seems work
Best regards
Jean-Marc
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
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Finding the actual position of a clicked word
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
HyperActive Software | http://www.hyperactivesw.com
Re: Finding the actual position of a clicked word
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Finding the actual position of a clicked word
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Finding the actual position of a clicked word
Just so everyone knows, that adorable method of finding (pseudo):
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
Code: Select all
the number of chunks from the beginning to the click|selected|whatever chunk...
Craig
-
- 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
Yet another option:
Use links (and get also the minus sign).
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).
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
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Finding the actual position of a clicked word
Hermann.
Not sure I get your idea. All words are now links, and a click in the field simply returns the clickChunk.
Craig
Not sure I get your idea. All words are now links, and a click in the field simply returns the clickChunk.
Craig
-
- 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
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).
The following, for example, increases/decreases each clicked number by 1 if clicked with shiftkey down/up.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Finding the actual position of a clicked word
Ah, I see. OK.