IB Statements/SetTimer

From CometWiki

Jump to: navigation, search

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.

  • Stop execution
  • Warn the user
  • Using the SatisfyInput command, supply a default response

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


Personal tools