Guidance
指路人
g.yi.org
Software / Reginald / Examples / TimeOut.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/* Timeout.rex -- This gets a time from the user at which he would
 * like this script to do something. The script then waits until
 * that time before it does that action.
 *
 * This is just an example, so the action we do is simply to end
 * this script.
 */


/* Ask him to enter the Hour and Minute to schedule an event */
SAY "Enter the Hour and Minute to schedule an event,"
SAY "for example, 10:45pm"
PULL scheduled

/* Make sure he entered it correctly */
IF LASTPOS('PM', scheduled) \= 0 THEN DO
	PARSE VAR scheduled hours ':' minutes 'PM' .
	pm = 'pm'
END
ELSE IF LASTPOS('AM', scheduled) \= 0 THEN DO
	PARSE VAR scheduled hours ':' minutes 'AM' .
	pm = 'am'
END
ELSE DO
	PARSE VAR scheduled hours ':' minutes .
	pm = 'pm'
END
hours = STRIP(hours)
minutes = STRIP(minutes)
IF hours = '' | DATATYPE(hours, 'W') = 0 THEN DO
bad:
	SAY "Entered time incorrectly"
	EXIT
END
IF minutes = '' | DATATYPE(minutes, 'W') = 0 THEN SIGNAL bad
SAY '"'||hours||'"'
SAY '"'||minutes||'"'
SAY '"'||pm||'"'

scheduled = hours || ':' || minutes || pm

/* Get the number of hours since midnight */
hours = TIME('H', scheduled, 'C')

/* Get the number of minutes since the top of the hour */
minutes = TIME('M', scheduled, 'C')

/* Calculate total minutes since midnight */
minutes = (hours * 60) + minutes

/* Get the current time */
current = TIME('C')

/* Get the number of hours since midnight */
curr_hours = TIME('H', current, 'C')

/* Get the number of minutes since the top of the hour */
curr_minutes = TIME('M', current, 'C')

/* Calculate total minutes since midnight */
curr_minutes = (curr_hours * 60) + curr_minutes

/* Is the time not yet past? */
IF curr_minutes <= minutes THEN DO

	/* Calculate the difference in seconds */
	seconds = (minutes - curr_minutes) * 60 

	SAY seconds

	/* Delay that many seconds */
	CALL SLEEP seconds

	/* It's time for our event */
	SAY "It's time!"

	/* Here you would do whatever action was supposed to be
	 * done at the designated time. For this example, all we
	 * do is EXIT.
	 */

END

ELSE SAY "The scheduled time has already passed!"

EXIT
掌柜推荐
 
 
¥420.00 ·
 
 
¥470.00 ·
 
 
¥890.00 ·
 
 
¥660.00 ·
 
 
¥748.00 ·
 
 
¥1,800.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-18 23:35:25