|
Thread: Sos
-
Jul 4th, 2003, 06:08 AM
#1
Thread Starter
New Member
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
-
Jul 4th, 2003, 06:22 AM
#2
Addicted Member
Sounds like the DateDiff function is what you need.
Use Now to get the system time.
Have two module level variables:
VB Code:
Dim mdLogInTime As Date
Dim mdLogOutTime As Date
When the user logs in:
When the user logs out:
VB Code:
mdLogOutTime = Now
' To display the time difference in minutes, for example...
MsgBox ("The User was logged in for " & DateDiff("m", mdLogInTime, mdLogOutTime)) & " minutes"
For more info do a search in Help for DateDiff.
-
Jul 4th, 2003, 06:25 AM
#3
Fanatic Member
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
-
Jul 4th, 2003, 06:41 AM
#4
Fanatic Member
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? 
-
Jul 4th, 2003, 01:39 PM
#5
If you decide to use GetTickCount you need to be aware that it resets to zero each midnight.
-
Jul 4th, 2003, 01:43 PM
#6
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
-
Jul 4th, 2003, 03:54 PM
#7
-
Jul 4th, 2003, 04:25 PM
#8
[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.
-
Jul 4th, 2003, 04:28 PM
#9
-
Jul 4th, 2003, 07:20 PM
#10
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"
-
Jul 5th, 2003, 12:47 AM
#11
Fanatic Member
Take a guess, if you didn't guess a programmer you were unfortunately wrong =(
"X-mas is 24.Desember you English morons.." - NoteMe
-
Jul 6th, 2003, 04:18 PM
#12
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|