Jump to content
xisto Community
Sign in to follow this  
it01y2

Timer is it possible in vb 6.0 to make a while statement which executes ever

Recommended Posts

Is it possible in vb 6.0 to make a while statement which executes every 10 minutes?
Any ideas?


Well, it's possible, but very ineffective... Insteda, you shoud look at API Guide... They have a complete list of API functions, and there are two that can be used for this what you need... They are advanced timer controls, and allow you to set a callback function, that will be called on interval you specify, and plus, it runs as a separate thread... I think they ahve something to do with quartz.dll... I'll try to find my old projects, and write you an example...

Edit:
I found a few good functions that you may find usefull:
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As CurrencyPrivate Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As CurrencyPrivate Sub WaitMs(ByVal MS As Long) 'wait a given number of millisecondsDim t21 As Currency, f21 As Currency, e21 As CurrencyQueryPerformanceFrequency f21  'get number of counts/secondt21 = f21 * MS / 1000# 'multiply f by number of seconds to get number of counts to waitQueryPerformanceCounter e21  'get current count numbere21 = e21 + t21  'add number of counts to wait to current countDo  QueryPerformanceCounter t21  If t21 > e21 Then Exit Do  'wait for current count to exceed e  DoEventsLoopEnd Sub

I'm still looking for that separate thread function

Edit 2:
I couldn;t find what I was looking for, but try looking at this example HERE... I think it has everything you need, and it's sort of multi thread for VB6... I think that's the best choice for you...
Edited by Galahad (see edit history)

Share this post


Link to post
Share on other sites

why not use a timer instead. You could put your codes on the on timer event. VB provides a timer to do it. i thinks that would perfectly fit for the job. :)

Share this post


Link to post
Share on other sites

why not use a timer instead. You could put your codes on the on timer event. VB provides a timer to do it. i thinks that would perfectly fit for the job. :)

He could, but Timer object isn't very precise... And if something occupies his program, Timer would miss his turn... So it wouldn't be 10 minutes, it would become 12 minutes... Multi-threading is the best way to go about, have an external process worry about minutes, and when the time comes, execute the code he needs... If on the other hand, those 10 mintes don't have to be 10 minutes, Timer object would be satisfactory...

Share this post


Link to post
Share on other sites

He could, but Timer object isn't very precise... And if something occupies his program, Timer would miss his turn... So it wouldn't be 10 minutes, it would become 12 minutes... Multi-threading is the best way to go about, have an external process worry about minutes, and when the time comes, execute the code he needs... If on the other hand, those 10 mintes don't have to be 10 minutes, Timer object would be satisfactory...

really??? but VB timer creates a different thread for its own execution. I've used it before for timer agents used in cafes and other apps that uses timers. I don't see any problem with it.

Share this post


Link to post
Share on other sites

really??? but VB timer creates a different thread for its own execution. I've used it before for timer agents used in cafes and other apps that uses timers. I don't see any problem with it.

Nah, generic VB6 Timer doesn't create it's own thread, and it isn't quite precise... Yes, it's satisfactory if you don't need exact time intervals in a millisecond, but when precision is of the essence, it fails misserably... I wrote a programm that needed precise time intervals to poll certain hardware, and Timer failed to do the job, I had to write a separate thread timer using API, to achieve 20ms precision...

Share this post


Link to post
Share on other sites

Nah, generic VB6 Timer doesn't create it's own thread, and it isn't quite precise... Yes, it's satisfactory if you don't need exact time intervals in a millisecond, but when precision is of the essence, it fails misserably... I wrote a programm that needed precise time intervals to poll certain hardware, and Timer failed to do the job, I had to write a separate thread timer using API, to achieve 20ms precision...

ahhh. I've never have had wrote a program that really needs a precise time. may I ask if you turn on and off your timer? I mean during each execution of the timer you turn it off and after its execution you turn it on...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.