HOME       >>       Programming

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


it01y2

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


Galahad

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...

moodsey211

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.


Galahad

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...

moodsey211

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.

Galahad

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...

moodsey211

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...


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.