Time entry

Peter Brigham MD pmbrig at gmail.com
Tue Feb 23 12:41:25 EST 2010


On Feb 22, 2010, at 1:21 PM, Peter Haworth wrote:

> ... and clock faces in general don't differentiate between AM and PM  
> times....

Here's a modification to handle AM/PM for the mousemove handler in the  
clock_behavior button script. What I added or changed is marked with  
comments:

local oldHour
/*** in addition to existing script locals ***/

on mouseMove X,Y
    if not allowDrag then exit mouseMove

    /***  start of addition 1 ***/
    put word -1 of fld "output" of me into AMorPM
    if AMorPM is not in "AM,PM" then
       /***  this if statement is only necessary the first time
              the handler is run in the revised version
              could be taken out after the output fld has
              AM or PM in it ***/
       put "AM" into AMorPM
    end if
    if oldHour = empty then
       set the itemdelimiter to ":"
       put item 1 of fld "output" of me into oldHour
       set the itemdelimiter to comma
    end if
    /***  end of addition 1 ***/

    put getAngle(X,Y) into A
    put angleToLoc(A,xLoc,yLoc,pRad) into hourLoc
    set points of grc "pointer" of me to xLoc,yLoc & cr & hourLoc
    put (round((185 - A)*2)div 15)*15 into tMin
    put trunc(tMin/60) into tHour
    if tHour = 0 then put 12 into tHour

    /***   start of addition 2 ***/
    if tHour = 12 and oldHour = 11 then
       doSwap AMorPM
    else if tHour = 11 and oldHour = 12 then
       doSwap AMorPM
    end if
    put tHour into oldHour
    /***  end of addition 2 ***/

    put tHour & ":" & format("%02s",tMin mod 60) && AMorPM into fld  
"output" of me
    /***  note addition of "&& AMorPM" in above line ***/
end mouseMove

    /***  additional handler
           swaps AM and PM, changes the variable AMorPM by reference  
***/

on doSwap @AMorPM
    put item itemoffset(AMorPM,"PM,AM") of "AM,PM" into AMorPM
end doSwap

> Either way, thanks a lot for the code.

Me too -- very cool implementation, Scott! I'm saving this one.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the use-livecode mailing list