Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay the number of times a program has run and its last run time
Keywordsdisplay, times run, last time
CategoriesTips and Tricks, Windows
 
Save the number of runs and the last time in the registry with the GetSetting and SaveSetting statements.
 
Private RunTimes As Long
Private RunDate As Date

Private Sub Form_Load()
    RunTimes = GetSetting("CounterApp", "Counts", _
        "NumTimes", 0) + 1
    RunDate = GetSetting("CounterApp", "Counts", _
        "LastTime", Now)
    If RunTimes > 1 Then
        lblTimes.Caption = "This program has been run " & _
            Format$(RunTimes) & " times."
        lblDate.Caption = "The last was at " & _
            Format$(RunDate) & "."
    Else
        lblTimes.Caption = "This is the program's first " & _
            "run."
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SaveSetting "CounterApp", "Counts", "NumTimes", RunTimes
    SaveSetting "CounterApp", "Counts", "LastTime", Now
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated