Results 1 to 7 of 7

Thread: [RESOLVED] Anything wrong with this code?

  1. #1

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Resolved [RESOLVED] Anything wrong with this code?

    Code:
    Private Declare Function timeGetTime Lib "winmm.dll" () As Long
    
    Private Sub Command1_Click()
    Dim SystemStartTimeDate As Data
    Ddayticked = timeGetTime / 1000 / 60 / 60 / 24 'min
    MsgBox DateValue(Now() - Ddayticked)
    MsgBox TimeValue(Now() - Ddayticked)
    
    End Sub
    the above will retrive the system started time and date.
    but it seems systems started before 25 or so shows incorrect system started date and its a feature date ex 10/15/2009 according to one of my client bug report

    screen shots :

    This is correct. it was taken using a 3rd party tool


    but,
    for the same, my above code shows

    system started date 10/13/2009 time: 3/18/34

    any problem with above code?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  3. #3

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Anything wrong with this code?

    Quote Originally Posted by RhinoBull View Post
    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.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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).
    Quote 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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Anything wrong with this code?

    Quote Originally Posted by LaVolpe View Post
    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.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Anything wrong with this code?

    Quote Originally Posted by Fazi View Post
    ... 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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Anything wrong with this code?

    Quote Originally Posted by LaVolpe View Post
    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
  •  



Click Here to Expand Forum to Full Width