Results 1 to 12 of 12

Thread: Sos

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    4

    Sos

    Please could someone help me out with how to calculate time difference start time and end time using system time automatically. Thats, the start time and end time are used automatically when the person logs in and out respectively using the person's system clock as the inputs. The difference betwen the two times are then calculated and stored/saved in a file located somewhere as log.
    This has been giving me too much headaches and would be glad to get over it, code snippets would be very lovely if anyone has any. Best regards to all

  2. #2
    Addicted Member Kezmondo's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    166
    Sounds like the DateDiff function is what you need.
    Use Now to get the system time.

    Have two module level variables:
    VB Code:
    1. Dim mdLogInTime As Date
    2. Dim mdLogOutTime As Date

    When the user logs in:
    VB Code:
    1. mdLogInTime = Now

    When the user logs out:
    VB Code:
    1. mdLogOutTime = Now
    2.  
    3. ' To display the time difference in minutes, for example...
    4. MsgBox ("The User was logged in for " & DateDiff("m", mdLogInTime, mdLogOutTime)) & " minutes"

    For more info do a search in Help for DateDiff.

  3. #3
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Put ur program in the startup entry in the registry.
    Then when ur program starts, record the time using
    GetTickCount API, and when ur program ends, record the
    time again using GetTickCount and calculate the difference.
    Caution, though: Be acknowledge who's closing ur program, the
    user or the system. This can be done through simple value
    checking in ur form_unload or through some APIs.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  4. #4
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    I would not recommend using DateDiff for what you are looking to do. Experimented with it when writing code for this purpose before and it was completely unreliable [it rounds seconds, minutes, hours very erratically]. So I wrote my own code to calculate time differences which you can find here [go to last posting at this link for the code that eliminates need for a Timer]: http://www.vbforums.com/showthread.php?threadid=245515

    What you can do is capture the current system time when the application starts. Then, in the Unload event, capture the current time again, use pieces of the code at the link just provided to calculate the difference in 'start' and 'end' times and then just write all your info to a log file.
    Do canibals not eat clowns because they taste funny?

  5. #5

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by MartinLiss
    If you decide to use GetTickCount you need to be aware that it resets to zero each midnight.
    I believe you are thinking of the Timer VB function Marty. GetTickCount starts from when you last restarted the computer.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    According to this thread :

    From MSDN :

    The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days.
    Last edited by manavo11; Jul 4th, 2003 at 04:28 PM.


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    [QUOTE]Originally posted by manavo11
    From MSDN :

    The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. [/Highlight]
    You're right.

  9. #9
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by MartinLiss
    You're right.


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    49.7 days? who the hell thought up that number? lol
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    Take a guess, if you didn't guess a programmer you were unfortunately wrong =(


    "X-mas is 24.Desember you English morons.." - NoteMe

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Posts
    4

    THANKS TO ALL THE CONTRIBUTORS

    I just want to thank all those that contributed to my "sos" problems I really appreciated ur prompt contributions. Have a lovely week. I will try those suggestions, hopefully they will work out well for me regards all

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