Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Time bug, anyone know why?

Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing the
time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling or
floor or rounding, noone hseems to have addressed the basic issue which is
why the time concept of 1/24 for an hour doesn't work; I suppose it could be
somethibng to do with rounding (is vba rounding the decimal up to the next
one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Time bug, anyone know why?

Here is one workaround using DateAdd

Dim dt As Date
dt = #1/1/2008 12:55:00 PM#
MsgBox DateAdd("h", 1, dt)

--
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison
Free & Pro versions


"Mark Stephens" wrote in message
...
Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing
the time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling
or floor or rounding, noone hseems to have addressed the basic issue which
is why the time concept of 1/24 for an hour doesn't work; I suppose it
could be somethibng to do with rounding (is vba rounding the decimal up to
the next one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Time bug, anyone know why?

Hi mark,

It is always advisable to post the actual code you have. However, the
following code appears to work OK.

Note that space and underscore at the end of a line is a line break in an
otherwise single line of code.

Sub testAddTime()

Dim timeNow As Date
Dim timeNext As Date

timeNow = Now()

'Both the following lines appear to work under test
'dateNext = dateNow + TimeValue("01:00:00")
timeNext = timeNow + 1 / 24

MsgBox Format(timeNow, "hh:mm:ss") & vbCrLf & _
Format(timeNext, "hh:mm:ss")

'Code for caption on ActiveX button
'(Button Created from Control Toolbox Toolbar)
ActiveSheet.CommandButton1.Caption = _
Format(timeNext, "hh:mm:ss")

'Code for a button created from Forms Toolbar
'Not sure if is best code practice.
ActiveSheet.Shapes("Button 3").Select
Selection.Characters.Text = Format(timeNext, "hh:mm:ss")
End Sub

--
Regards,

OssieMac


"Mark Stephens" wrote:

Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing the
time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling or
floor or rounding, noone hseems to have addressed the basic issue which is
why the time concept of 1/24 for an hour doesn't work; I suppose it could be
somethibng to do with rounding (is vba rounding the decimal up to the next
one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Time bug, anyone know why?

Hi, thanks for that, I trie d the first version and it has the same
phenomena... it increments by 1 hour and one minute rather than just one
hour (which is very strange).

I actually had the button caption display Now, and the message box now +
TimeValue("01:00:00")

The timne now (the button) displayed 16:16 and the message box 17:17 which
is pretty bizarre although i am sure there's an explanation for it
somewhere. i even modified it to make the timeNext = timeNext - 1 minute
(1/24/60) but still made no difference!

Regards, Mark



"OssieMac" wrote in message
...
Hi mark,

It is always advisable to post the actual code you have. However, the
following code appears to work OK.

Note that space and underscore at the end of a line is a line break in an
otherwise single line of code.

Sub testAddTime()

Dim timeNow As Date
Dim timeNext As Date

timeNow = Now()

'Both the following lines appear to work under test
'dateNext = dateNow + TimeValue("01:00:00")
timeNext = timeNow + 1 / 24

MsgBox Format(timeNow, "hh:mm:ss") & vbCrLf & _
Format(timeNext, "hh:mm:ss")

'Code for caption on ActiveX button
'(Button Created from Control Toolbox Toolbar)
ActiveSheet.CommandButton1.Caption = _
Format(timeNext, "hh:mm:ss")

'Code for a button created from Forms Toolbar
'Not sure if is best code practice.
ActiveSheet.Shapes("Button 3").Select
Selection.Characters.Text = Format(timeNext, "hh:mm:ss")
End Sub

--
Regards,

OssieMac


"Mark Stephens" wrote:

Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's
the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing
the
time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem
to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling
or
floor or rounding, noone hseems to have addressed the basic issue which
is
why the time concept of 1/24 for an hour doesn't work; I suppose it could
be
somethibng to do with rounding (is vba rounding the decimal up to the
next
one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Time bug, anyone know why?

On Thu, 19 Feb 2009 14:14:34 +0800, "Mark Stephens" wrote:

Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing the
time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling or
floor or rounding, noone hseems to have addressed the basic issue which is
why the time concept of 1/24 for an hour doesn't work; I suppose it could be
somethibng to do with rounding (is vba rounding the decimal up to the next
one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark



Please post the exact code you are using. I cannot replicate your problem
here.
--ron


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Time bug, anyone know why?

Hi again Mark,

The example as I gave it to you works perfectly for me.

Your quote: "I actually had the button caption display Now, and the message
box now + TimeValue("01:00:00")"

You cannot display the value of now in one line and then in another line add
something to Now and expect that it will always return a value exactly
incremented by the value added.

There is a time delay between the two even though it might be small; the
delay is there. The actual time of Now could be in the phase of moving from
one minute to the next.

You need to assign Now to a variable the way I did it so that it is fixed
and then add something to the variable if you want it to return a value
exactly incremented by the added time.

Anyway, please post the exact code you have as per Ron's suggestion and
maybe can test a little more.

--
Regards,

OssieMac


"Mark Stephens" wrote:

Hi, thanks for that, I trie d the first version and it has the same
phenomena... it increments by 1 hour and one minute rather than just one
hour (which is very strange).

I actually had the button caption display Now, and the message box now +
TimeValue("01:00:00")

The timne now (the button) displayed 16:16 and the message box 17:17 which
is pretty bizarre although i am sure there's an explanation for it
somewhere. i even modified it to make the timeNext = timeNext - 1 minute
(1/24/60) but still made no difference!

Regards, Mark



"OssieMac" wrote in message
...
Hi mark,

It is always advisable to post the actual code you have. However, the
following code appears to work OK.

Note that space and underscore at the end of a line is a line break in an
otherwise single line of code.

Sub testAddTime()

Dim timeNow As Date
Dim timeNext As Date

timeNow = Now()

'Both the following lines appear to work under test
'dateNext = dateNow + TimeValue("01:00:00")
timeNext = timeNow + 1 / 24

MsgBox Format(timeNow, "hh:mm:ss") & vbCrLf & _
Format(timeNext, "hh:mm:ss")

'Code for caption on ActiveX button
'(Button Created from Control Toolbox Toolbar)
ActiveSheet.CommandButton1.Caption = _
Format(timeNext, "hh:mm:ss")

'Code for a button created from Forms Toolbar
'Not sure if is best code practice.
ActiveSheet.Shapes("Button 3").Select
Selection.Characters.Text = Format(timeNext, "hh:mm:ss")
End Sub

--
Regards,

OssieMac


"Mark Stephens" wrote:

Hi all,

I am trying to increment a time for a shceduling feature in my program. I
want to increase the time by 1 hour each time i click a button. Here's
the
methodology:

1. Read the cell containing the system date and time

2. Add to the number (1/24)

3. Update the button caption


It's pretty simple really but what happens is that instead of increasing
the
time by an hour as intended it increases it by 1 hour and one minute!
Frustrating and annoying. Adjusting the increment slightly doesn't seem
to
have much effect at all. I have done some searching on google in this
newsgroup and whilst i have found some workarounds such as using ceiling
or
floor or rounding, noone hseems to have addressed the basic issue which
is
why the time concept of 1/24 for an hour doesn't work; I suppose it could
be
somethibng to do with rounding (is vba rounding the decimal up to the
next
one minute incrememtn automatically?) seems strange any
suggestions/explanations/workarounds gratwefully received.

Thanks and regards, Mark







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time calculations for Scheduled Time vs. Actual Time Worked The Caterer Excel Discussion (Misc queries) 1 November 29th 09 08:08 AM
straight time, time and a half, and double time Jeremy Excel Discussion (Misc queries) 3 September 23rd 08 09:03 PM
Calculate Ending time using Start Time and Elapsed Time Chief 711 Excel Worksheet Functions 5 May 13th 08 04:34 PM
Comparing 2 files on date/time stamp, and based time difference do a subroutine [email protected] Excel Programming 1 September 28th 07 03:53 AM
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM


All times are GMT +1. The time now is 03:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"