#119738 - 2004-05-18 12:08 PM
Do Until - I think
|
Richie19Rich77
Seasoned Scripter
   
Registered: 2002-08-16
Posts: 624
Loc: London, England
|
Hi All
I have a KiXForms script that opens up a GUI with 3 buttons to click, but I also have a countdown timer from 5 to 0, and when it hits 0, it will automatically do the function of one of the buttons.
So I have come up with the following, but it does not allow me to click on a button while it is processing the function.
Of course there must me another way, but I need a liitle help 
Thanks
Code:
Function Run_Click() $x=5 Do Sleep 1 $Panel3.Text = $x $x = $x - 1 Until $Stop = 1 OR $x = 0 EndFunction
|
|
Top
|
|
|
|
#119739 - 2004-05-18 01:11 PM
Re: Do Until - I think
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You need to get out of the "linear" progamming thought process 
You need to allow the form to process events, and check the event queue while waiting for the countdown to expire. At the moment your function hijacks the processing, so nothing else can occur.
Probably the easiest way is to design a mechanism which allows you to register / deregister functions and call them in each loop of your main event processing code.
You then need to design your functions so that they check their state and exit asap rather than loop internally.
This means that you need to preserve state information between calls, probably by using global variables.
Unless KF has an alarm handler built-in?
|
|
Top
|
|
|
|
#119740 - 2004-05-18 01:40 PM
Re: Do Until - I think
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
... $Button1 = $Form.Controls.Button("OK", 276, 160, 105, 20) $Button1.Anchor = 10 $Button1.OnClick = "OK" ... $Timer1 = $System.Timer() $Timer1.Interval = 1000 *60 * 2 ;milliseconds * seconds * minutes $Timer1.OnTick = "OK()" ... ... subform.show $Timer1.Start() ... Function OK $Timer1.Stop() ... endfunction
|
|
Top
|
|
|
|
#119741 - 2004-05-18 02:07 PM
Re: Do Until - I think
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well that makes it easier.
If you want your display to countdown, fire a countdown function at 1 second interval which decrements the countdown text field. When the countdown text field reaches zero fire the "button pressed" function.
Something like:
Code:
...
$Button1 = $Form.Controls.Button("OK", 276, 160, 105, 20)
$Button1.Anchor = 10
$Button1.OnClick = "Button1_Clicked"
...
$Timer1 = $System.Timer()
$Timer1.Interval = 1000 * 1 * 1 ;milliseconds * seconds * minutes
$Timer1.OnTick = "Countdown()"
...
...
subform.show
$Timer1.Start()
...
Function Button1_Clicked()
$Timer1.Stop()
...
EndFunction
Function CountDown()
$Panel3.Text = Val($Panel3.Text) - 1
If Val($Panel3.Text) < 1 Button1_Clicked() EndIf
EndFunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|