IB Statements/SetTimer
From CometWiki
(added code example) |
m (minor) |
||
(3 intermediate revisions not shown) | |||
Line 2: | Line 2: | ||
There are many times that you may want to get some information from the user but there are records extracted, or some other reason that would ''mess things up'' if the user did not provide the information in a timely manor. | There are many times that you may want to get some information from the user but there are records extracted, or some other reason that would ''mess things up'' if the user did not provide the information in a timely manor. | ||
- | With the SetTimer statement, you can limit the time a user has to input the | + | With the SetTimer statement, in conjunction with [[IB_Statements/eventwait|Comet Event Handling]], you can limit the time a user has to input the data, and take some action. |
<table cellpadding=5 cellspacing=2> | <table cellpadding=5 cellspacing=2> | ||
<td><b>Syntax:</b> | <td><b>Syntax:</b> | ||
<td> | <td> | ||
- | SetTimer TimerName, Duration | + | SetTimer TimerName$, Duration |
- | Where TimerName | + | Where TimerName$ may be a string expression and Duration may be a numeric expression. |
</td> | </td> | ||
<tr> | <tr> | ||
Line 18: | Line 18: | ||
* Stop execution | * Stop execution | ||
* Warn the user | * Warn the user | ||
- | * Using the SatisfyInput command, supply a default response | + | * Using the [[Mnemonics_"S"#.28SatisfyInput.29|SatisfyInput]] command, supply a default response |
- | SetTimer will fire from an Input statement, Wait statement, or EventWait statement. | + | SetTimer will fire from an [[Input]] statement, [[IB_Statements/wait|Wait]] statement, or [[IB_Statements/eventwait|EventWait]] statement. |
+ | |||
+ | If multiple timeouts occur and there is no event handler in effect, a single timer event will fire. | ||
+ | |||
+ | If the program uses [[IB Statements/UserDefinedProcs|Comet Procedures]], the event handler should be part of the main code. | ||
+ | |||
+ | To stop the timer, use the following: | ||
+ | SetTimer "", 0 | ||
</td> | </td> | ||
Line 35: | Line 42: | ||
SetTimer "Timer 1: "+Term$, 10*10*10 ! One Second | SetTimer "Timer 1: "+Term$, 10*10*10 ! One Second | ||
print @(0,9);'enter something' | print @(0,9);'enter something' | ||
- | input @(1,10) a$ | + | Do |
- | + | input @(1,10) a$ | |
- | + | if a$ = "" goto EndIt | |
+ | print @(0,10);(cfld);@(0,11);'you entered ';a$ | ||
Loop | Loop | ||
- | + | EndIt: | |
SetTimer "", 0 | SetTimer "", 0 | ||
EventSub | EventSub | ||
print @(0,15);'done' & wait | print @(0,15);'done' & wait | ||
- | + | Stop | |
TimerFunc: | TimerFunc: | ||
Line 50: | Line 58: | ||
Print (mc);@(0,5);(rb);"Source: " ; EventSource$ ; " Event: " ; EventName$ ; "(";Count;")";(rc) | Print (mc);@(0,5);(rb);"Source: " ; EventSource$ ; " Event: " ; EventName$ ; "(";Count;")";(rc) | ||
EventSub TimerFunc EventSource$ EventName$ | EventSub TimerFunc EventSource$ EventName$ | ||
- | + | Return | |
</td> | </td> | ||
</table> | </table> |
Latest revision as of 20:31, 22 July 2010
Introduction
There are many times that you may want to get some information from the user but there are records extracted, or some other reason that would mess things up if the user did not provide the information in a timely manor.
With the SetTimer statement, in conjunction with Comet Event Handling, you can limit the time a user has to input the data, and take some action.
Syntax: |
SetTimer TimerName$, Duration Where TimerName$ may be a string expression and Duration may be a numeric expression. |
Discussion: |
The SetTimer instruction causes an event to be fired to the program when a specified duration (in Milliseconds) has passed.In the event handler, the program has the opportunity to do several things.
SetTimer will fire from an Input statement, Wait statement, or EventWait statement. If multiple timeouts occur and there is no event handler in effect, a single timer event will fire. If the program uses Comet Procedures, the event handler should be part of the main code. To stop the timer, use the following: SetTimer "", 0 |
Example: |
Length 254 & Local EventSource$, EventName$ length 80 & local a$ Length 5.0 & Local Count Clear Print (cs) EventSub TimerFunc EventSource$ EventName$ SetTimer "Timer 1: "+Term$, 10*10*10 ! One Second print @(0,9);'enter something' Do input @(1,10) a$ if a$ = "" goto EndIt print @(0,10);(cfld);@(0,11);'you entered ';a$ Loop EndIt: SetTimer "", 0 EventSub print @(0,15);'done' & wait Stop TimerFunc: Count = Count + 1 Print (mc);@(0,5);(rb);"Source: " ; EventSource$ ; " Event: " ; EventName$ ; "(";Count;")";(rc) EventSub TimerFunc EventSource$ EventName$ Return
|