Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Timer


6 replies to this topic

#1 it01y2

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 71 posts

Posted 08 July 2008 - 04:49 PM

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

Any ideas?

#2 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

Posted 13 July 2008 - 09:27 PM

View Postit01y2, on Jul 8 2008, 06:49 PM, said:

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 Currency
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Currency

Private Sub WaitMs(ByVal MS As Long) 'wait a given number of milliseconds
Dim t21 As Currency, f21 As Currency, e21 As Currency
QueryPerformanceFrequency f21  'get number of counts/second
t21 = f21 * MS / 1000# 'multiply f by number of seconds to get number of counts to wait
QueryPerformanceCounter e21  'get current count number
e21 = e21 + t21  'add number of counts to wait to current count
Do
  QueryPerformanceCounter t21
  If t21 > e21 Then Exit Do  'wait for current count to exceed e
  DoEvents
Loop
End 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, 13 July 2008 - 09:39 PM.


#3 moodsey211

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 40 posts
  • Gender:Male
  • Location:Cebu City Philippines

Posted 14 July 2008 - 01:09 AM

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

#4 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

Posted 19 July 2008 - 04:08 AM

View Postmoodsey211, on Jul 14 2008, 03:09 AM, said:

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

#5 moodsey211

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 40 posts
  • Gender:Male
  • Location:Cebu City Philippines

Posted 21 July 2008 - 06:48 AM

View PostGalahad, on Jul 19 2008, 12:08 PM, said:

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.

#6 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

Posted 23 July 2008 - 09:44 PM

View Postmoodsey211, on Jul 21 2008, 08:48 AM, said:

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

#7 moodsey211

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 40 posts
  • Gender:Male
  • Location:Cebu City Philippines

Posted 25 July 2008 - 03:11 AM

View PostGalahad, on Jul 24 2008, 05:44 AM, said:

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




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users