Page 1 of 1 1
Topic Options
#119738 - 2004-05-18 12:08 PM Do Until - I think
Richie19Rich77 Offline
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 Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#119741 - 2004-05-18 02:07 PM Re: Do Until - I think
Richard H. Administrator Offline
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
#119742 - 2004-05-18 02:34 PM Re: Do Until - I think
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Thanks Richard & Rad, just to a meeting and they don't want a front end menu, so I have had to scrap that idea.

But thanks for the info, and i will use it in some other project.

Thanks

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.064 seconds in which 0.035 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org