Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you add a Timer to a Module or Class Module 1

Status
Not open for further replies.

PoyPoy

Programmer
Oct 16, 2000
7
NL
Hi guys,

I am trying to run a command that will execute every 30 minutes. To achieve this, I used a counter (Integer) and a Timer (Interval: 60’000).

However, the problem lies, that I would like to run this function “form independent”, i.e. executing anywhere the user finds himself within the application.

I could not get it to work running it through a form. When focus changes between other forms, the timer stops running.

Any help would be appreciated.

Thanks.
 
You can use the API Sleep function:
Code:
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim lMinutes as Long
Dim lmSec as Long

lMinutes = 30#
lmSec = lMinutes * 60 * 1000

Sleep lmSec

 
Thanks dsi,

Where do I place this sub, i am a bit confused, as I've never used API Calls.

rgds.
 
You can load but dont show a small form with a timer on it that reads the time of day once every 10 seconds.(10000ms)
To start the 30 minute interval, store the time + 30 minutes [RememberTime=dateadd("n",30,Now())] as a global variant.
Have this in the timer1_timer sub: [If DateDiff(Now(),RememberTime)>0 then Sub GoAndDoWhatYouWantedTo]
 
The DECLARE SUB statement goes in the top of a module or class. The rest of the code can go anywhere you want to call SLEEP from.
 
Thanks Guys,

But unfortunately, I still can't get it to work. I have added the declare statement to the top of a class module, but get the following error message:

“Compile Error:

Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.”

Any help is greatly appreciated.
 
Many Thanks,

I managed to get it working using the CodeFlow.dll

rgds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top