i need timer interval more than 1 Minute.

T

Tark Siala

hi
i am using timer control, its good but if my event doing less than one time
in 1 Minute.
i want make event every 5 minute, how i can do that?

i am using VB6, VB.NET

--
Best Regards

Tark M. Siala
Development Manager
INTERNATIONAL COMPUTER CENTER (ICC.Networking)
Mobile: +218-91-3125900
E-Mail: (e-mail address removed)
Messenger: (e-mail address removed)
Web Page: http://www.icc-libya.com
Blog: http://spaces.msn.com/tarksiala
======================================
 
J

Jason

in VB.net (not sure about 6...)

a timer with the interval of 1000 = 1000ms which = 1 s

so for 1 minute 60 * 1000 = 60,000

so for 5 minutes 60 * 5000 = 300,000
 
S

Sankalp

You can assign the interval of your timer on form load to some value.
e.g. if your timer is Timer1, then
on form load :-
Timer1.Enabled = True
Timer1.Interval = 300000 ( 5 minutes)

This will fire the Timer1_Elapsed event where you can do your
processing.

-S
 
B

Bob Butler

Jason said:
in VB.net (not sure about 6...)

a timer with the interval of 1000 = 1000ms which = 1 s

so for 1 minute 60 * 1000 = 60,000

so for 5 minutes 60 * 5000 = 300,000

In VB6 the timer control is limited to 65535 so the usual method there is to
save the time ina module-level or static procedure level variable, set the
timer to 60000 (or any value >0 and <65536) and then when the timer event
fires compare "Now" to the saved time to determine if you have reached the
desired interval.
 
K

Karl E. Peterson

Sankalp said:
You can assign the interval of your timer on form load to some value.
e.g. if your timer is Timer1, then
on form load :-
Timer1.Enabled = True
Timer1.Interval = 300000 ( 5 minutes)

Not in ClassicVB, you can't!
 
S

Saga

This is what happens when the query is crossposted to Classic and .NET
groups :)

Regards
Saga
 
K

Ken Halter

Jason said:
perhaps its time for an upgrade? ;)

Nah... you'll find out the first time that 5 minutes is up and the OS has
swallowed a timer event <g>

Personally, I set the tick to about once per second (depending on a few
things) and use DateDiff to figure out if a certain amount of time has
elapsed. Timer events are just to flakey to rely on. By doing the math
myself, I eliminate the OSs ability (for the most part) to ruin my timing.
 
P

PulsarSL

dim interval as long
dim ticked as long

long = 30000 'or your time, in seconds
ticked=0

Private Sub Timer1_Timer()
ticked = ticked + 1
if ticked = interval then call yourfunction
end sub
 
K

Karl E. Peterson

dim interval as long
dim ticked as long

long = 30000 'or your time, in seconds
ticked=0

Private Sub Timer1_Timer()
ticked = ticked + 1
if ticked = interval then call yourfunction
end sub

Yeah, that's one idea (though I'd use Static procedure vars, myself), but as
others have pointed out this method is vulnerable. You are hearby
admonished to write, 1000 times, on the blackboard:

"Windows is not a real-time operating system."
"Windows is not a real-time operating system."
"Windows is not a real-time operating system."
"Windows is not a real-time operating system."
"Windows is not a real-time operating system."
"Windows is not a real-time operating system."
 
R

Rich M

I usually set the Interval to 60000 (1 minute) and use the Timer's Tag
property as a minute counter:

Private Sub Timer1_Timer()
If Val(Timer1.Tag) < 4 Then
' Increment minute counter
Timer1.Tag = Val(Timer1.Tag) + 1
Else
' Do actual stuff every 5 minutes

' Reset minute counter
Timer1.Tag = "0"
End If
End Sub
 
C

Cor Ligthert [MVP]

Tark,

In VBNet in at least 3 (4) different methods. This dependend if you use it
for a Form, a windowsservice or a multithreading application. For Webforms
will in the Atlas part as well a clientside timer be included.

Beside that can you in windowforms VBNet as well stop the processing one
minute or longer and get mostly the same effect.

I hope this helps,

Cor
 
J

J French

hi
i am using timer control, its good but if my event doing less than one time
in 1 Minute.
i want make event every 5 minute, how i can do that?
i am using VB6, VB.NET

For VB (not B#) I would set the interval to about 1 sec or less

and set up module variable as :-

TargetTime = DateAdd( "n", 5, Now )

In the Timer Tick just check for

If Now >= TargetTime Then ...
 
B

Bob Butler

Rich M said:
LOL - it works

Except that it really doesn't. With the vagaries of the timer firing it
tends to drift further and further from the desired intervals. Checking Now
against a target time keeps it more accurate over a longer time span if
that's important.
 
M

Michael C

Rich M said:
LOL - it works

It does work but the complexity of what happens underneath is quite large.
It will do something like this:
- Retreive the timer.tag as a string
- Val will convert that to double
- the 1 is a 16bit int and will be converted to a double
- add the 2 together as doubles
- convert the result back to a string
- put the result back into the timer tag

on the other hand incrementing a module level variable will simply do an
increment which will be a single cpu instruction (the above would be
literally hundreds). While I don't think it's worth concerning yourself
overly with this sort of thing it is worth taking into account and not
writing inefficient code just because it's the same amount of typing. Once a
project got large if this sort of thing was used throughout it could bloat
it considerably.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top