Board index » Visual Studio » Timer and Time

Timer and Time

Visual Studio334
Hi,



I have another issue.



I have a timer on the main form in VB 6.



On form load the system if the SQL have any records it will open the

frmWarning. This is working fine.



If the user closes the frmWarning without fixing the problem the timer is

activated. The time the user closes the form, the "t" is set to the current

time in munites. Now if the minutes is 47 current time then t= 47+35 =82, I

am adding plus 35 so that the program will open the frmWarning again after

35 minutes, there is no such minutes as 82, because the "s" at the bottom

after 59 its value will be 0 . What can I do to fix this and make it work?



Thanks

Dib





Dim s,t

'On Form Load



t = Format(Time, "N") + 35

Timer1.Enabled = True

Timer1.Interval = 100

Timer1.Enabled = True

DoEvents

frmWarning.Show

frmWarning.ZOrder





'Timer sub

s = Format(Time, "N") - 1

If t = s Then

t = Format(Time, "N") + 35

frmWarning.Show



' Timer1.Enabled = True

ElseIf t>Format(Time, "N") - 1 Then

' Timer1.Enabled = False

End If


-
 

Re:Timer and Time

First, I would delcare your variables a little more specifically. Merely

using Dim s,t defaults them to Variants which at best is unreliable. I

would declare them as dates which handles both date and time data



Dim t as Date

Dim s as Date



Afterwhich, the easiest way to determine the difference between two dates

and/or times is the DateDiff function. Also, I would consider using the

DateAdd function to add time to a variable instead of merely using basic

addition.



HTH



- Kevin Provance





-

Re:Timer and Time

If you use



t= (47+35) mod 60



t will hold the minutes following the hour wrap if the two numbers are more

than 60. If less than 60 t will equal the total.



--



Randy Birch

MS MVP Visual Basic

vbnet.mvps.org/">vbnet.mvps.org/

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

Read. Decide. Sign the petition to Microsoft.

classicvb.org/petition/">classicvb.org/petition/

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







"Dib" <NOTdibsSPAM@comNOSPAMcast.net>wrote in message

: Hi,

:

: I have another issue.

:

: I have a timer on the main form in VB 6.

:

: On form load the system if the SQL have any records it will open the

: frmWarning. This is working fine.

:

: If the user closes the frmWarning without fixing the problem the timer is

: activated. The time the user closes the form, the "t" is set to the

current

: time in munites. Now if the minutes is 47 current time then t= 47+35 =82,

I

: am adding plus 35 so that the program will open the frmWarning again after

: 35 minutes, there is no such minutes as 82, because the "s" at the bottom

: after 59 its value will be 0 . What can I do to fix this and make it work?

:

: Thanks

: Dib

:

:

: Dim s,t

: 'On Form Load

:

: t = Format(Time, "N") + 35

: Timer1.Enabled = True

: Timer1.Interval = 100

: Timer1.Enabled = True

: DoEvents

: frmWarning.Show

: frmWarning.ZOrder

:

:

: 'Timer sub

: s = Format(Time, "N") - 1

: If t = s Then

: t = Format(Time, "N") + 35

: frmWarning.Show

:

: ' Timer1.Enabled = True

: ElseIf t>Format(Time, "N") - 1 Then

: ' Timer1.Enabled = False

: End If

:

:



-

Re:Timer and Time

Thanks

Dib



"Randy Birch" <rgb_removethis@mvps.org>wrote in message

Quote
If you use



t= (47+35) mod 60



t will hold the minutes following the hour wrap if the two numbers are

more

than 60. If less than 60 t will equal the total.



--



Randy Birch

MS MVP Visual Basic

vbnet.mvps.org/">vbnet.mvps.org/

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

--

Read. Decide. Sign the petition to Microsoft.

classicvb.org/petition/">classicvb.org/petition/

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

--







"Dib" <NOTdibsSPAM@comNOSPAMcast.net>wrote in message

news:%23VI73mPLFHA.3420@tk2msftngp13.phx.gbl...

: Hi,

:

: I have another issue.

:

: I have a timer on the main form in VB 6.

:

: On form load the system if the SQL have any records it will open the

: frmWarning. This is working fine.

:

: If the user closes the frmWarning without fixing the problem the timer

is

: activated. The time the user closes the form, the "t" is set to the

current

: time in munites. Now if the minutes is 47 current time then t= 47+35

=82,

I

: am adding plus 35 so that the program will open the frmWarning again

after

: 35 minutes, there is no such minutes as 82, because the "s" at the

bottom

: after 59 its value will be 0 . What can I do to fix this and make it

work?

:

: Thanks

: Dib

:

:

: Dim s,t

: 'On Form Load

:

: t = Format(Time, "N") + 35

: Timer1.Enabled = True

: Timer1.Interval = 100

: Timer1.Enabled = True

: DoEvents

: frmWarning.Show

: frmWarning.ZOrder

:

:

: 'Timer sub

: s = Format(Time, "N") - 1

: If t = s Then

: t = Format(Time, "N") + 35

: frmWarning.Show

:

: ' Timer1.Enabled = True

: ElseIf t>Format(Time, "N") - 1 Then

: ' Timer1.Enabled = False

: End If

:

:







-

Re:Timer and Time

Thanks

Dib



"Casey Provance" <casey@tpasoft.com>wrote in message

Quote
First, I would delcare your variables a little more specifically. Merely

using Dim s,t defaults them to Variants which at best is unreliable. I

would declare them as dates which handles both date and time data



Dim t as Date

Dim s as Date



Afterwhich, the easiest way to determine the difference between two dates

and/or times is the DateDiff function. Also, I would consider using the

DateAdd function to add time to a variable instead of merely using basic

addition.



HTH



- Kevin Provance









-