|
-
Oct 2nd, 2009, 07:56 AM
#1
[RESOLVED] Anything wrong with this code?
-
Oct 2nd, 2009, 08:04 AM
#2
Re: Anything wrong with this code?
Try this instead:
Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Sub Form_Load()
Dim myStartTime As Long
myStartTime = timeGetTime / 1000
Debug.Print DateAdd("s", -myStartTime, Now)
End Sub
-
Oct 2nd, 2009, 08:14 AM
#3
Re: Anything wrong with this code?
 Originally Posted by RhinoBull
Try this instead:
Code:
Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Sub Form_Load()
Dim myStartTime As Long
myStartTime = timeGetTime / 1000
Debug.Print DateAdd("s", -myStartTime, Now)
End Sub
rinobull,
yah your one also works correct in my pc which booted just 2 hours ago.
ill send this code as exe to my client whos computer started before 25 days ago and bring the result.
Last edited by Fazi; Oct 2nd, 2009 at 08:18 AM.
-
Oct 2nd, 2009, 09:07 AM
#4
Re: Anything wrong with this code?
Note that timeGetTime and GetTickCount and possibly other windows timing APIs will reset after a pc has been on continuously for approximately 50 days. The value may also be negative if => 2^31 (return value is signed whereas unsigned within the O/S).
 Originally Posted by msdn
Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days.
Source page
Edited: You mentioned 25 days as a marker. Look at this:
The max positive value of a Long is: 2147483647 (approx 24.855 days)
The nr of ms for 25 days is: 2160000000 (assuming I did my math correctly)
This means that I would expect the return value form timeGetTime to be a negative value (unsigned "Long" value converted to signed)
Last edited by LaVolpe; Oct 2nd, 2009 at 09:36 AM.
-
Oct 2nd, 2009, 11:38 AM
#5
Re: Anything wrong with this code?
 Originally Posted by LaVolpe
Note that timeGetTime and GetTickCount and possibly other windows timing APIs will reset after a pc has been on continuously for approximately 50 days. The value may also be negative if => 2^31 (return value is signed whereas unsigned within the O/S).
Source page
Edited: You mentioned 25 days as a marker. Look at this:
The max positive value of a Long is: 2147483647 (approx 24.855 days)
The nr of ms for 25 days is: 2160000000 (assuming I did my math correctly)
This means that I would expect the return value form timeGetTime to be a negative value (unsigned "Long" value converted to signed)
yes volp, i was aware of that 49days max limit by this function 
btw,
if i am correct,
in
myStartTime = timeGetTime / 1000
&
Ddayticked = timeGetTime / 1000 / 60 / 60 / 24 'min
the left most variables never get numbers in milli seconds. either in seconds or in hours or even days.
according my little math or programming knowledge 
so no problem of declaring it as long.
for 25 days you get 2160000 seconds only right.
-
Oct 2nd, 2009, 02:04 PM
#6
Re: Anything wrong with this code?
 Originally Posted by Fazi
... for 25 days you get 2160000 seconds only right.
No. The value of timeGetTime starts at negative as returned from the API, if more than 24.855 days since last booted. I would convert signed to unsigned (which will be a double) then divide by 1000.
-
Oct 3rd, 2009, 11:56 PM
#7
Re: Anything wrong with this code?
 Originally Posted by LaVolpe
No. The value of timeGetTime starts at negative as returned from the API, if more than 24.855 days since last booted. I would convert signed to unsigned (which will be a double) then divide by 1000.
undestood
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|