473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Setting a timer

This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of curent
hour.

But I want to calculate the next tick time whenever I want to start the
timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval untill 35
in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
14 2538
PSEUDO - Hope this helps - Regards OHM#

Dim FirstTick As Boolean = True
Dim TimeNow as New DateTime = Now
Dim MinuteNow As Int32 = TimeNow.GetMinute
Dim InterimInterval As Int32

While MinuteNow < 15
MinuteNow = TimeNow.GetMinute
Loop

InterimInterval = 10 - ( MinuteNow MOD 10 )

Set Timer = InterimInterval

Sub On TimerTick

If FirstTick The
Set Timer Interval = 10
FirstTick = False
End If

End Sub





Crirus wrote:
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of
curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #2
2 remarks if i may ;p

1 i think timenow never gets a new value so the loop will never end (update
it in the while loop)

2 it looks like the while loop will run non stop, in the while loop call
doevents or a sleep
i don't think users would be happy when they click the button at 13:01 and
have to wait 14mins to do anithing w their pc

alternative could be working w 2 timers start the first one when the user
clicks set it for 1min intervals and when the MinuteNow < 15 is reached
launch the second one w 10min itervals and stop the first one.

hope it helps

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
PSEUDO - Hope this helps - Regards OHM#

Dim FirstTick As Boolean = True
Dim TimeNow as New DateTime = Now
Dim MinuteNow As Int32 = TimeNow.GetMinute
Dim InterimInterval As Int32

While MinuteNow < 15
MinuteNow = TimeNow.GetMinute
Loop

InterimInterval = 10 - ( MinuteNow MOD 10 )

Set Timer = InterimInterval

Sub On TimerTick

If FirstTick The
Set Timer Interval = 10
FirstTick = False
End If

End Sub





Crirus wrote:
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of
curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?


Regards - OHM# On**********@BTInternet.com

Nov 20 '05 #3
This was untested PSEUDO Code. The intention is clear even if the syntax is
not correct. When I write 'Actual' code, you can come back and criticise me
OK

Replace this with . . As PSEUDO
While MinuteNow < 15
MinuteNow = Now.GetMinute
Loop

OHM#

EricJ wrote:
2 remarks if i may ;p

1 i think timenow never gets a new value so the loop will never end
(update it in the while loop)

2 it looks like the while loop will run non stop, in the while loop
call doevents or a sleep
i don't think users would be happy when they click the button at
13:01 and have to wait 14mins to do anithing w their pc

alternative could be working w 2 timers start the first one when the
user clicks set it for 1min intervals and when the MinuteNow < 15 is
reached launch the second one w 10min itervals and stop the first one.

hope it helps

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:OF**************@TK2MSFTNGP12.phx.gbl...
PSEUDO - Hope this helps - Regards OHM#

Dim FirstTick As Boolean = True
Dim TimeNow as New DateTime = Now
Dim MinuteNow As Int32 = TimeNow.GetMinute
Dim InterimInterval As Int32

While MinuteNow < 15
MinuteNow = TimeNow.GetMinute
Loop

InterimInterval = 10 - ( MinuteNow MOD 10 )

Set Timer = InterimInterval

Sub On TimerTick

If FirstTick The
Set Timer Interval = 10
FirstTick = False
End If

End Sub





Crirus wrote:
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15
of curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?


Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #4
Well, I dont think I need two timers...
If I can start the timer in order to raise tick event exact as if it was
started at base start time (minute 15) the problem is solved without any
boolean or second timer

All I need is to figure out how many minutes I still need to wait until
first tick

So if I enable the timer at minute 33 of curent hour, I need to set the
interval to 2 minutes in order to haev first tick at minute 35

If I enable the timer on minute 10, I have to wait 5 minute untill first
ticck should occur, on minute 15..and so one

All I need is that interval that is first wait, considering hte interval and
base tick minute (e.g. 15)

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in message
news:ub****************@TK2MSFTNGP09.phx.gbl...
This was untested PSEUDO Code. The intention is clear even if the syntax is not correct. When I write 'Actual' code, you can come back and criticise me OK

Replace this with . . As PSEUDO
While MinuteNow < 15
MinuteNow = Now.GetMinute
Loop

OHM#

EricJ wrote:
2 remarks if i may ;p

1 i think timenow never gets a new value so the loop will never end
(update it in the while loop)

2 it looks like the while loop will run non stop, in the while loop
call doevents or a sleep
i don't think users would be happy when they click the button at
13:01 and have to wait 14mins to do anithing w their pc

alternative could be working w 2 timers start the first one when the
user clicks set it for 1min intervals and when the MinuteNow < 15 is
reached launch the second one w 10min itervals and stop the first one.

hope it helps

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:OF**************@TK2MSFTNGP12.phx.gbl...
PSEUDO - Hope this helps - Regards OHM#

Dim FirstTick As Boolean = True
Dim TimeNow as New DateTime = Now
Dim MinuteNow As Int32 = TimeNow.GetMinute
Dim InterimInterval As Int32

While MinuteNow < 15
MinuteNow = TimeNow.GetMinute
Loop

InterimInterval = 10 - ( MinuteNow MOD 10 )

Set Timer = InterimInterval

Sub On TimerTick

If FirstTick The
Set Timer Interval = 10
FirstTick = False
End If

End Sub





Crirus wrote:
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15
of curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com

Nov 20 '05 #5
"Crirus" <Cr****@datagroup.ro> schrieb
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of
curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

It does not calculate the 2 minutes, but it should work:

Private Sub StartTimer()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Function IsAlarmMinute(ByVal Minute As Integer) As Boolean
Return ((Minute + 5) Mod 10) = 0
End Function

Private Sub Timer1_Tick( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Timer1.Tick

If IsAlarmMinute(DateTime.Now.Minute) Then
Debug.WriteLine("feed me!")
End If
End Sub
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
You could use this logic. . . .

Regards - OHM#

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim minute As Int32

Dim interval As Int32

For minute = 0 To 60

Select Case minute

Case 0 To 4

interval = 5 - minute

Case 6 To 14

interval = 15 - minute

Case 16 To 24

interval = 25 - minute

Case 26 To 34

interval = 35 - minute

Case 36 To 44

interval = 45 - minute

Case 46 To 54

interval = 55 - minute

Case 56 To 60

interval = 5 + (60 - minute)

Case 5, 15, 25, 35, 45, 55

interval = 10

End Select

Debug.WriteLine("Minute: " & minute & " - Interval = " & interval)

Next

End Sub

Prints This Out . . .

Minute: 0 - Interval = 5

Minute: 1 - Interval = 4

Minute: 2 - Interval = 3

Minute: 3 - Interval = 2

Minute: 4 - Interval = 1

Minute: 5 - Interval = 10

Minute: 6 - Interval = 9

Minute: 7 - Interval = 8

Minute: 8 - Interval = 7

Minute: 9 - Interval = 6

Minute: 10 - Interval = 5

Minute: 11 - Interval = 4

Minute: 12 - Interval = 3

Minute: 13 - Interval = 2

Minute: 14 - Interval = 1

Minute: 15 - Interval = 10

Minute: 16 - Interval = 9

Minute: 17 - Interval = 8

Minute: 18 - Interval = 7

Minute: 19 - Interval = 6

Minute: 20 - Interval = 5

Minute: 21 - Interval = 4

Minute: 22 - Interval = 3

Minute: 23 - Interval = 2

Minute: 24 - Interval = 1

Minute: 25 - Interval = 10

Minute: 26 - Interval = 9

Minute: 27 - Interval = 8

Minute: 28 - Interval = 7

Minute: 29 - Interval = 6

Minute: 30 - Interval = 5

Minute: 31 - Interval = 4

Minute: 32 - Interval = 3

Minute: 33 - Interval = 2

Minute: 34 - Interval = 1

Minute: 35 - Interval = 10

Minute: 36 - Interval = 9

Minute: 37 - Interval = 8

Minute: 38 - Interval = 7

Minute: 39 - Interval = 6

Minute: 40 - Interval = 5

Minute: 41 - Interval = 4

Minute: 42 - Interval = 3

Minute: 43 - Interval = 2

Minute: 44 - Interval = 1

Minute: 45 - Interval = 10

Minute: 46 - Interval = 9

Minute: 47 - Interval = 8

Minute: 48 - Interval = 7

Minute: 49 - Interval = 6

Minute: 50 - Interval = 5

Minute: 51 - Interval = 4

Minute: 52 - Interval = 3

Minute: 53 - Interval = 2

Minute: 54 - Interval = 1

Minute: 55 - Interval = 10

Minute: 56 - Interval = 9

Minute: 57 - Interval = 8

Minute: 58 - Interval = 7

Minute: 59 - Interval = 6

Minute: 60 - Interval = 5


Crirus wrote:
Well, I dont think I need two timers...
If I can start the timer in order to raise tick event exact as if it
was started at base start time (minute 15) the problem is solved
without any boolean or second timer

All I need is to figure out how many minutes I still need to wait
until first tick

So if I enable the timer at minute 33 of curent hour, I need to set
the interval to 2 minutes in order to haev first tick at minute 35

If I enable the timer on minute 10, I have to wait 5 minute untill
first ticck should occur, on minute 15..and so one

All I need is that interval that is first wait, considering hte
interval and base tick minute (e.g. 15)
"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:ub****************@TK2MSFTNGP09.phx.gbl...
This was untested PSEUDO Code. The intention is clear even if the
syntax is not correct. When I write 'Actual' code, you can come back
and criticise me OK

Replace this with . . As PSEUDO
While MinuteNow < 15
MinuteNow = Now.GetMinute
Loop

OHM#

EricJ wrote:
2 remarks if i may ;p

1 i think timenow never gets a new value so the loop will never end
(update it in the while loop)

2 it looks like the while loop will run non stop, in the while loop
call doevents or a sleep
i don't think users would be happy when they click the button at
13:01 and have to wait 14mins to do anithing w their pc

alternative could be working w 2 timers start the first one when the
user clicks set it for 1min intervals and when the MinuteNow < 15 is
reached launch the second one w 10min itervals and stop the first
one.

hope it helps

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:OF**************@TK2MSFTNGP12.phx.gbl...
PSEUDO - Hope this helps - Regards OHM#

Dim FirstTick As Boolean = True
Dim TimeNow as New DateTime = Now
Dim MinuteNow As Int32 = TimeNow.GetMinute
Dim InterimInterval As Int32

While MinuteNow < 15
MinuteNow = TimeNow.GetMinute
Loop

InterimInterval = 10 - ( MinuteNow MOD 10 )

Set Timer = InterimInterval

Sub On TimerTick

If FirstTick The
Set Timer Interval = 10
FirstTick = False
End If

End Sub





Crirus wrote:
> This is more a logical problem than a VB.
>
> I have this situation:
>
> A timer that need to tick at each 10 minutes starting on minute 15
> of curent hour.
>
> But I want to calculate the next tick time whenever I want to
> start the timer.
>
> So, I have ticks on minutes 25, 35, 45, 55, 05
>
> If I start the timer on minute 33 I need that 2 minutes interval
> untill 35 in order to start the timer..
> On tick event I reset the interval to 10 minutes.
> How to calculate that 2 minute interval?

Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #7
This is a different approach than the OP wanted. What you have done is
caused a 1Minute tick and determined if it is an alarm minute. However, the
logic does work because I tested it

I guess its up to him.

Regards - OHM#
Armin Zingler wrote:
"Crirus" <Cr****@datagroup.ro> schrieb
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of
curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

It does not calculate the 2 minutes, but it should work:

Private Sub StartTimer()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Function IsAlarmMinute(ByVal Minute As Integer) As Boolean
Return ((Minute + 5) Mod 10) = 0
End Function

Private Sub Timer1_Tick( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Timer1.Tick

If IsAlarmMinute(DateTime.Now.Minute) Then
Debug.WriteLine("feed me!")
End If
End Sub


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #8
Cor
Hi Crirus,

I should not write this because maybe a lot of comments,
But why not just threading.thread.sleep(600000) for the 10 minutes and the
first time the difference from now till the interval?

Cor
I have this situation:
A timer that need to tick at each 10 minutes starting on minute 15 of curent hour.
But I want to calculate the next tick time whenever I want to start the
timer.
So, I have ticks on minutes 25, 35, 45, 55, 05
If I start the timer on minute 33 I need that 2 minutes interval untill 35
in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

Nov 20 '05 #9
That is too particular
I could have any base start minute and any interval of events occurence...
and of course any enabling minute of an hour
So I really need to calculate what is the first minute after Now.Minute when
the event should occur as it was started at baseStartMinute

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:uL****************@TK2MSFTNGP09.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
This is more a logical problem than a VB.

I have this situation:

A timer that need to tick at each 10 minutes starting on minute 15 of
curent hour.

But I want to calculate the next tick time whenever I want to start
the timer.

So, I have ticks on minutes 25, 35, 45, 55, 05

If I start the timer on minute 33 I need that 2 minutes interval
untill 35 in order to start the timer..
On tick event I reset the interval to 10 minutes.
How to calculate that 2 minute interval?

It does not calculate the 2 minutes, but it should work:

Private Sub StartTimer()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Function IsAlarmMinute(ByVal Minute As Integer) As Boolean
Return ((Minute + 5) Mod 10) = 0
End Function

Private Sub Timer1_Tick( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Timer1.Tick

If IsAlarmMinute(DateTime.Now.Minute) Then
Debug.WriteLine("feed me!")
End If
End Sub
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10
"Crirus" <Cr****@datagroup.ro> schrieb
That is too particular
I could have any base start minute and any interval of events
occurence...
and of course any enabling minute of an hour
So I really need to calculate what is the first minute after
Now.Minute when the event should occur as it was started at
baseStartMinute


Of course you can replace the constants 5 and 10 by variables. The code also
works with every start minute, so does the code really not work the way you
need it?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #11
"One Handed Man [ OHM# ]" <On**********@BTInternet.com> schrieb
This is a different approach than the OP wanted.
Why?
What you have done
is caused a 1Minute tick
1 second tick. :)
and determined if it is an alarm minute.
yes, but why not? Waiting for a certain minute value can only be done by a)
using a timer checking the minute e.g. each second, or b) running in a loop
and check the minute value.
However, the logic does work because I tested it

I guess its up to him.


Yes

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #12
I'm writing this right now (not testet):

Private TickInterval as Integer=10

Private Sub StartTimer(ByVal BaseTickMinute As Integer, ByVal Interval As
Integer)
myTimer.Interval=FirstSleep(BaseTickMinute,Interva l)
myTimer.Start()
End Sub

'Return first interval for tick event
Private Function FirstSleep(ByVal BaseTickMinute As Integer, ByVal
Interval As Integer) As Integer
Dim nextTickMinute As Integer
Dim thisMinute As Integer = Now.Minute
If thisMinute > BaseTickMinute Then
nextTickMinute = Math.Ceiling((thisMinute - BaseTickMinute) /
Interval) * Interval
Return nextTickMinute - thisMinute
Else
nextTickMinute = Math.Ceiling((60 - BaseTickMinute + thisMinute)
/ Interval) * Interval
Return nextTickMinute - thisMinute
End If
End Function

Private Sub GameTick_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
GameTick.Interval = tickInterval * 60000
' Code here
End Sub

I will test later to see if it work

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
"Crirus" <Cr****@datagroup.ro> schrieb
That is too particular
I could have any base start minute and any interval of events
occurence...
and of course any enabling minute of an hour
So I really need to calculate what is the first minute after
Now.Minute when the event should occur as it was started at
baseStartMinute
Of course you can replace the constants 5 and 10 by variables. The code

also works with every start minute, so does the code really not work the way you need it?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #13
"Crirus" <Cr****@datagroup.ro> wrote in message
news:ez**************@TK2MSFTNGP11.phx.gbl...
.. . .
A timer that need to tick at each 10 minutes starting on minute 15
of curent hour. .. . . If I start the timer on minute 33 I need that 2 minutes interval untill 35
in order to start the timer..
How to calculate that 2 minute interval?


Over-simple Solution: Don't bother!

Timer's are realtively light-weight. It's what the likes of you and I
/do/ with them that kills machines ;-)

Use a Timer that fires once /every minute/ and check the current
minute each time around. If it matches your criteria, do whatever
it is that needs doing.

Sub tmrPoll_Elapsed( ...
tmrPoll.Enabled = False ' Just habit...

Select Case System.DateTime.Now().Minute
Case 5, 15, 25, 35, 45, 55
DoSomethingUseful()
End Select

tmrPoll.Enabled = True
End Sub

If you want to make this smart enough so that it /doesn't/ start up
until ??:15 if you launch the program at, say, ??:02, that's up to you.

HTH,
Phill W.
Nov 20 '05 #14
On Fri, 12 Dec 2003 11:10:45 -0000, One Handed Man [ OHM# ] wrote:
You could use this logic. . . .

Regards - OHM#

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim minute As Int32

Dim interval As Int32

For minute = 0 To 60

Select Case minute

Case 0 To 4

interval = 5 - minute

Case 6 To 14

interval = 15 - minute

Case 16 To 24

interval = 25 - minute

Case 26 To 34

interval = 35 - minute

Case 36 To 44

interval = 45 - minute

Case 46 To 54

interval = 55 - minute

Case 56 To 60

interval = 5 + (60 - minute)

Case 5, 15, 25, 35, 45, 55

interval = 10

End Select

Debug.WriteLine("Minute: " & minute & " - Interval = " & interval)

Next

End Sub

Prints This Out . . .

Minute: 0 - Interval = 5

Minute: 1 - Interval = 4

Minute: 2 - Interval = 3

Minute: 3 - Interval = 2

Minute: 4 - Interval = 1

Minute: 5 - Interval = 10

Minute: 6 - Interval = 9

Minute: 7 - Interval = 8

Minute: 8 - Interval = 7

Minute: 9 - Interval = 6

Minute: 10 - Interval = 5

Minute: 11 - Interval = 4

Minute: 12 - Interval = 3

Minute: 13 - Interval = 2

Minute: 14 - Interval = 1

Minute: 15 - Interval = 10

Minute: 16 - Interval = 9

Minute: 17 - Interval = 8

Minute: 18 - Interval = 7

Minute: 19 - Interval = 6

Minute: 20 - Interval = 5

Minute: 21 - Interval = 4

Minute: 22 - Interval = 3

Minute: 23 - Interval = 2

Minute: 24 - Interval = 1

Minute: 25 - Interval = 10

Minute: 26 - Interval = 9

Minute: 27 - Interval = 8

Minute: 28 - Interval = 7

Minute: 29 - Interval = 6

Minute: 30 - Interval = 5

Minute: 31 - Interval = 4

Minute: 32 - Interval = 3

Minute: 33 - Interval = 2

Minute: 34 - Interval = 1

Minute: 35 - Interval = 10

Minute: 36 - Interval = 9

Minute: 37 - Interval = 8

Minute: 38 - Interval = 7

Minute: 39 - Interval = 6

Minute: 40 - Interval = 5

Minute: 41 - Interval = 4

Minute: 42 - Interval = 3

Minute: 43 - Interval = 2

Minute: 44 - Interval = 1

Minute: 45 - Interval = 10

Minute: 46 - Interval = 9

Minute: 47 - Interval = 8

Minute: 48 - Interval = 7

Minute: 49 - Interval = 6

Minute: 50 - Interval = 5

Minute: 51 - Interval = 4

Minute: 52 - Interval = 3

Minute: 53 - Interval = 2

Minute: 54 - Interval = 1

Minute: 55 - Interval = 10

Minute: 56 - Interval = 9

Minute: 57 - Interval = 8

Minute: 58 - Interval = 7

Minute: 59 - Interval = 6

Minute: 60 - Interval = 5


Crirus wrote:
Well, I dont think I need two timers...
If I can start the timer in order to raise tick event exact as if it
was started at base start time (minute 15) the problem is solved
without any boolean or second timer

All I need is to figure out how many minutes I still need to wait
until first tick

So if I enable the timer at minute 33 of curent hour, I need to set
the interval to 2 minutes in order to haev first tick at minute 35

If I enable the timer on minute 10, I have to wait 5 minute untill
first ticck should occur, on minute 15..and so one

All I need is that interval that is first wait, considering hte
interval and base tick minute (e.g. 15)
"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:ub****************@TK2MSFTNGP09.phx.gbl...
This was untested PSEUDO Code. The intention is clear even if the
syntax is not correct. When I write 'Actual' code, you can come back
and criticise me OK

Replace this with . . As PSEUDO
While MinuteNow < 15
MinuteNow = Now.GetMinute
Loop

OHM#

EricJ wrote:
2 remarks if i may ;p

1 i think timenow never gets a new value so the loop will never end
(update it in the while loop)

2 it looks like the while loop will run non stop, in the while loop
call doevents or a sleep
i don't think users would be happy when they click the button at
13:01 and have to wait 14mins to do anithing w their pc

alternative could be working w 2 timers start the first one when the
user clicks set it for 1min intervals and when the MinuteNow < 15 is
reached launch the second one w 10min itervals and stop the first
one.

hope it helps

"One Handed Man [ OHM# ]" <On**********@BTInternet.com> wrote in
message news:OF**************@TK2MSFTNGP12.phx.gbl...
> PSEUDO - Hope this helps - Regards OHM#
>
> Dim FirstTick As Boolean = True
> Dim TimeNow as New DateTime = Now
> Dim MinuteNow As Int32 = TimeNow.GetMinute
> Dim InterimInterval As Int32
>
> While MinuteNow < 15
> MinuteNow = TimeNow.GetMinute
> Loop
>
> InterimInterval = 10 - ( MinuteNow MOD 10 )
>
> Set Timer = InterimInterval
>
> Sub On TimerTick
>
> If FirstTick The
> Set Timer Interval = 10
> FirstTick = False
> End If
>
> End Sub
>
>
>
>
>
>
>
>
>
>
>
>
>
> Crirus wrote:
>> This is more a logical problem than a VB.
>>
>> I have this situation:
>>
>> A timer that need to tick at each 10 minutes starting on minute 15
>> of curent hour.
>>
>> But I want to calculate the next tick time whenever I want to
>> start the timer.
>>
>> So, I have ticks on minutes 25, 35, 45, 55, 05
>>
>> If I start the timer on minute 33 I need that 2 minutes interval
>> untill 35 in order to start the timer..
>> On tick event I reset the interval to 10 minutes.
>> How to calculate that 2 minute interval?
>
> Regards - OHM# On**********@BTInternet.com

Regards - OHM# On**********@BTInternet.com


Regards - OHM# On**********@BTInternet.com


May I offer this solution:

Private Function GetInterval(ByVal min As Integer) As Integer
Dim iNext As Integer
iNext = ((min \ 10) * 10) + 5
If (min Mod 10) > 5 Then iNext += 10

If (iNext - min) = 0 Then
Return 10
Else
Return (iNext - min)
End If
End Function

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: yaktipper | last post by:
VS.NET 2002, framework 1.0 I wrote a very simple program to display the RGB value and x,y mouse position at the cursor on a 50ms timer. I noticed a memory leak of 8K per timer event. The leak...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
2
by: Ben Fidge | last post by:
Using Visual Studio 2005, how would I go about creating an application-wide timer hosted in global.asax? There's certain processes I want to run every couple of minutes and have had success using...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
2
by: shaunastirling | last post by:
Using Access 2003 how do i set a timer that automatically closes after the timer is up.
2
by: phpmagesh | last post by:
Hi to all, I have created a page with login and logout. i used session to register the login user and when he clicks in logout, it will destroy the session. this is nice but if system is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.