Page 1 of 2

clickLine

Posted: Tue Oct 22, 2013 5:06 pm
by garyth123
Hi,

I am trying to get clickLine to work as per:

Code: Select all

   
select the clickLine
put the value of the clickLine into tLine
put word 1 of line tLine of fld "facility use" into tTime
this is in a touchEnd handler but is not working.

Can anyone suggest what I might be doing wrong?

Thanks.

Re: clickLine

Posted: Tue Oct 22, 2013 5:23 pm
by Klaus
Hi garyth,

is this an editable field or is it locked?


Best

Klaus

Re: clickLine

Posted: Tue Oct 22, 2013 5:35 pm
by garyth123
Klaus wrote:Hi garyth,

is this an editable field or is it locked?


Best

Klaus
Hi Klaus,

It is locked.

I have just seen what the problem is. The line to be clicked contains linkText (with the intention of course that the user will click one of the links). Somehow clickLine doesn't work in this circumstance. However if I click on another part of the line which doesn't have linkText set clickLine works. However I need the user to click a link and at the same time to get the first word of the line.

[edit] I mean that there are pieces of text with their textStyle set to be link.

Any ideas how to get this working?

Thanks.

Re: clickLine

Posted: Tue Oct 22, 2013 11:15 pm
by dunbarx
Hi.

Linktext will not prevent the process from working. That said, the the way you have written your code snippet, are you sure that the "value of the clickLine" is an integer? The code will break if not. I do not know how your clickable field is ordered, but if it is 1,2,3, then It would be much more robust if you used:

word 2 of the clickline

since this is not dependent on the text.

But is any of this helpful? You mentioned that clicking on ordinary text does not cause a problem. I just want to make sure that something other than your idea of linked text is not lurking somewhere, because if your linked text resolves to a number, then:

put the value of the clickLine into tLine --if this is an integer, linkedText or not...
put word 1 of line tLine of fld "facility use" into tTime --then this will work

Put a breakpoint at the "put word 1..." line, and see if tLine is an integer

Craig Newman

Re: clickLine

Posted: Wed Oct 23, 2013 10:17 pm
by jacque
Without trying it, it almost sounds like a linkClicked message is being sent and somehow cancelling out the clickline function.

Do you have a linkClicked handler? Does it get triggered?

Re: clickLine

Posted: Thu Oct 24, 2013 9:57 am
by garyth123
jacque wrote:Without trying it, it almost sounds like a linkClicked message is being sent and somehow cancelling out the clickline function.

Do you have a linkClicked handler? Does it get triggered?
Hi Jacque,


I made a test stack yesterday to investigate what Craig was suggesting and of course the link text worked with clickLine just as Craig said.

I do have a linkClicked handler, as I need to do something when the user clicks on the text with textStyle set to link, so am interested if you can shed any light on what is wrong.

Here is what I currently have in the touchEnd handler:

Code: Select all

...
put word 1 of the value of the clickLine into tTime
put the clickChunk into tClickedText
linkClicked tClickedText
linkClicked invokes a function that needs both tTime and tClickedText as parameters.

Thanks.

Re: clickLine

Posted: Thu Oct 24, 2013 2:08 pm
by garyth123
Attached is a test stack which attempts to investigate how linkClicked and clickLine may effect each other.

Code: Select all

local aVar

on mouseUp
   --testLink
   f1
   answer "aVar is " & aVar with "Ok"
   --testLink
end mouseUp

on f1
   put word 1 of the value of the clickLine into aVar
end f1

--on linkClicked pLinkText
--   beep
--end linkClicked

--on testLink
--   put the clickChunk into tClickedText
--   linkClicked tClickedText
--   answer tClickedText
--end testLink
with the code as presented above ie linkClicked commented out, clickLine will work and return the first word of the line regardless of where on the line the click occurs ie clicking on a link makes no difference.

Uncommenting testLink and linkClicked and clicking a line

For text
1. testLink works for text and the clickChunk is returned
2. the value of the clickLine is not returned and neither answer dialog box opens

For a link
1. testLink does not work and the clickChunk is not returned
2. the value of the clickLine is not returned and neither answer dialog box opens

it doesn't seem to matter where testLink is called.

Even with testLink commented out but linkClicked uncommented the same behaviour for links as noted above occurs, which puzzles me.

Has anyone seen anything like this before? Or, more likely, what mistake am I making here in regard to the use of the above commands?

Sorry can't seem to attach a stack!

Re: clickLine

Posted: Thu Oct 24, 2013 2:15 pm
by garyth123
Here's a screenshot of the stack I attempted to attach. Can someone explain how to attach stacks in the forums. Thanks.

Re: clickLine

Posted: Thu Oct 24, 2013 2:21 pm
by dunbarx
Hi.

Good thinking, but you are getting ahead of yourself a bit. You cannot get the returned value of "avar" as written. When one handler calls another, the variables within each are local to that handler.
There are several ways around this:

1- Rewrite "f1" as a function, so that it will return a value to the calling handler.
2- Declare a script local variable so that all handlers in that script will know about it:

Code: Select all

on mouseUp
   --testLink
   f1
   answer "aVar is " & aVar with "Ok"
   --testLink
end mouseUp

on f1
   put word 1 of the value of the clickLine into aVar
end f1
There are others.

Craig

Re: clickLine

Posted: Thu Oct 24, 2013 2:34 pm
by garyth123
Hi,

Do you mean for me to do this:

Code: Select all

local aVar

on mouseUp
   testLink
   put f1() into aVar
   answer "aVar is " & aVar with "Ok"
   --testLink
end mouseUp

function f1
   local tVar
   
   put word 1 of the value of the clickLine into tVar
   
   return tVar
end f1

on linkClicked pLinkText
   beep
end linkClicked

on testLink
   put the clickChunk into clickedText
   linkClicked clickedText
   answer clickedText
end testLink
this doesn't appear to change things but perhaps I'm not understanding what you mean?

Re: clickLine

Posted: Thu Oct 24, 2013 3:31 pm
by garyth123
Okay here is what I'm looking at now:

Code: Select all

local firstWord

on mouseUp
   --answer "text clicked is " & testLink() with "Ok"
   put f1() into firstWord
   answer "firstWord is " & firstWord with "Ok"
   --answer "text clicked is " & testLink() with "Ok"
end mouseUp

function f1
   local tVar
   
   put word 1 of the value of the clickLine into tVar
   
   return tVar
end f1

--on linkClicked pLinkText
--   beep
--   answer "clickedText is " & pLinkText with "Ok"
--end linkClicked

--function testLink
--   put the clickChunk into clickedText
--   linkClicked clickedText

--   return clickedText
--end testLink
with linkClicked commented out and the calls to testLink in the mouseUp handler also commented out this works and returns the first word of the value of the clickLine regardless of where one clicks -- white space, text, or link.

With the two lines to the calls to testLink in the mouseUp handler commented out and the function definition for testLink also commented out, but with the linkClicked handler uncommented:

clicking on text returns

"firstWord is text" or "firstWord is link" as appropriate -- this is what I'd expect

however clicking on a link returns

"clickedText is text" or "clickedText is link" as appropriate. Ie although I'm calling f1() which returns the value of the clickLine I seem to be getting the clickChunk but not in the form of start char to end char but the actual text clicked.

I hope this is clear and that someone can point out what I need to do to get round this seeming problem. Thanks.

Re: clickLine

Posted: Thu Oct 24, 2013 3:55 pm
by dunbarx
Hi.

You need to practice using functions. The parameters that accompany these calls are integral to them. In special cases, something like your "f1()" has meaning, but not here. This is all good stuff, in that you are playing with handler sets that call each other and perform their own tasks.

That said, the rationale for doing that is to localize functionality, both for readability and portability. But oftentimes this is simply not required. I have lost the thread of what you are trying to do. What is missing from the following, placed in the script of your locked field with the textStyle of some of the text set to "link"?

Code: Select all

on mouseUp
   if the textstyle of the clickChunk = "link" then
      put the clickText into tText
      put the clickChunk into tChunk
      doYourThing
   else
      dontDoYourThing  --clicked text is not a group text
   end if
end mouseUp
doYourThing (or dont) being processes that you want to run.

Craig

Re: clickLine

Posted: Thu Oct 24, 2013 4:16 pm
by garyth123
Basically I am trying to launch an action when a user clicks on a link and at the same time getting the first word of the line in which the link occurs. The clicked text and the first word of the line are parameters (among others) to the function which carries out the action I wish to initiate. So in the actual stack/app that I'm working on I have a need to work with functions and parameters.

I'll take on board what you're saying about my needing to understand these things more.

Thanks.

Re: clickLine

Posted: Thu Oct 24, 2013 5:14 pm
by dunbarx
OK.

You are starting a process (a handler call), then, rather than obtaining a value of some sort (a function call). You can do this either way, and I highly recommend that you do so. The exercise at this stage is more important than the result.

So you can:

Code: Select all

on mouseUp
   if the textstyle of the clickChunk = "link" then
      put word 1 of the clickLine into tLine
      yourFunction tLine
   end if
end mouseUp

on yourHandler tLine
   answer tLine
  doYourThing
end yourHandler
See how the handler call is made? There are more complex ways to do this, but here there is no need. But the process can also be run wholly in the mouseUp handler itself. There may be no need for a separate handler call. Up to you, though.

Craig

Re: clickLine

Posted: Thu Oct 24, 2013 10:05 pm
by garyth123
Let's see if I have understood what I need to do:

I have a card which contains a locked field with a number of lines.

The lines look like the following with different times for each 10 minute interval of an hour:

0750 book x1 book x2 book x3 book x4
0800 book x1 book x2 book x3 book x4
0810 book x1 book x2 book x3 book x4

the x1, x2, etc are the links which the user will click, and that will invoke a function, to make a booking.

1. user clicks a link (x1 say) to book a time for a certain number of participants.
1.1. the text clicked contains the number of participants (=1)
1.2. the first word of the line contains the time (0750 say)

As I understand it I therefore need to use a linkClicked message. I have placed the call to the function that makes the booking (via a web service) inside the linkClicked handler. The required number of participants and the time for the booking are required parameters for this booking function.

However in order to get the first word of the line I need to use the clickLine function and this does not appear to work in the situation in which there is a linkClicked message being passed. I have the linkClicked in my stack script. If this is commented out I can get clickLine to return its value from a call to it from touchEnd, but never when the linkClicked handler is "live" so to speak.

So, does anybody have any ideas about what I can do to get both to work together. Sorry Craig if I seem to be misunderstanding what you are saying.