Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KEEPING TRACK OF PROGRAM USAGE

Status
Not open for further replies.

MrVB50au

Programmer
Mar 16, 2003
326
0
0
AU
Hi Everyone,
I have in my program
For instance, if a user goes to work on Monday and sees that a program was last run on Saturday--when he was at the beach--he'll know that someone else was using the program. Here's how I implemented a technique for keeping track of program usage. The technique uses the Windows registry to store information.

First I defined constants for the application name and section used for locating information in the registry:

Code:
Const APP_NAME = "MyAppName"
Const SECTION_NAME = "Usage"

Then, placed the following code where it will execute each time the program is run. In the main form's Load event procedure. This code converts the current date and time to a string and stores it in the registry under the "Last used" key:
Code:
SaveSetting APP_NAME, SECTION_NAME, "Last used", CStr(Now)

Finally, I had to have code to read the registry value and display the information to the user. Here's an example of how I did this:
Code:
Private Sub MainForm_Load()
    Dim LastUse As String
    LastUse = GetSetting(APP_NAME, SECTION_NAME, _
    "Last used")
    If LastUse = "" Then
        MsgBox "This program has not been run before."
    Else
        MsgBox "This program was last run " & LastUse
    End If 
End Sub

I had to put it before the call to SaveSetting.

Now, I need a little additional programming to keep track of when the program was started and stopped and how much total time it was running but can't think for the life of me on how.

Be great if anyone has the time to help, would be really appriciated.

Thanks in advance,

Andrew.



 
In your Main Form Load just store the time in a global variable or in the registry then in the Main form's QueryUnload store the time again and the difference between the 2 times will be your total time ran.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top