Board Logo
« function to wait for specific time period »

Welcome Guest. Please Login or Register.
Sep 23rd, 2017, 3:13pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: function to wait for specific time period  (Read 461 times)
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 247
xx function to wait for specific time period
« Thread started on: Jul 23rd, 2016, 12:54am »

hi,
two functions are given below with example code which wait for
specified time period in (milli seconds) one written using timer and other written using time$ function.
Code:
while 1
k=k+1
print "line";k,
t=waitfor1(1000)
print"hello world"
t=waitfor2(1000)
wend
'---------------------------------------
function waitfor1(ts)
timer ts, [itHappened]
wait
[itHappened]
timer 0
scan
waitfor1=1
end function
'---------------------------------
function waitfor2(ts)
t1=time$("ms")
while ts>time$("ms")-t1
wend
k=1
if k goto[yes]
wait
[yes]
scan
waitfor2=1
end function
 
User IP Logged

ezprogramming
Guest
xx Re: function to wait for specific time period
« Reply #1 on: Jul 23rd, 2016, 05:27am »

Post deleted
« Last Edit: Sep 15th, 2016, 1:41pm by ezprogramming » User IP Logged

zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 247
xx Re: function to wait for specific time period
« Reply #2 on: Sep 12th, 2016, 12:07am »

There is a command wait(t) which makes control to wait t sec in foxpro .I borrowed that idea to write waitfor functions to make use of timer simple thus avoiding to write more lines of code.
The very reason for usage of scan is given in the help section of timer under subheading Be Careful.
If I set timer 1000 there are two possible things to happen:
1. it (the timer) should sit aside for 1000ms otherwise
there would be a time difference DT<>0 while triggering the events. or
2. The control Should jump from one process to other and that should happen within a span of t<1ms.
If the possibility 2 is true then waitfor1() is much better than waitfor2().
I think nothing is there in the help section of JB about this.
How the button click can fall out of scope when waitfor1() is used without modification can you elaborate it?
« Last Edit: Sep 14th, 2016, 07:44am by zzz000abc » User IP Logged

Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3089
xx Re: function to wait for specific time period
« Reply #3 on: Sep 12th, 2016, 01:32am »

The WAIT and SCAN statements do not just handle events triggered within the function or sub, they will act on ANY event. If the event is a button press with a [label] that exists outside the function or sub your code will fail.

In general to gain proper control of events you must switch them off if you don't want them to fire.
User IP Logged

zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 247
xx Re: function to wait for specific time period
« Reply #4 on: Sep 14th, 2016, 07:45am »

thank you rod it's more clear now.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls