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
 
 
 
 
 
 
TitleMake a program do something special the first time it runs
Keywordsone time task, startup, first time
CategoriesWindows, Software Engineering
 
Save a value in the registry that the program can use to tell if it has run before. If the value is not present when the program starts, perform the special action.
 
Private Sub Form_Load()
Dim user_name As String

    ' See if we have run before by getting the user's
    ' name from the registry.
    user_name = GetSetting("OneTime", "Settings", _
        "UserName", "")
    If Len(user_name) > 0 Then
        ' We have run before. Display a welcome message.
        lblWelcome.Caption = "Welcome " & user_name & "!"
        txtName.Visible = False
        cmdOk.Top = lblWelcome.Top + lblWelcome.Height + 120
    Else
        ' We have not run before. Get the user name.
        cmdOk.Top = txtName.Top + txtName.Height + 120
    End If

    Height = cmdOk.Top + cmdOk.Height + 120 + Height - _
        ScaleHeight
End Sub

Private Sub cmdOk_Click()
    ' If the user entered a name, save it.
    If Len(Trim$(txtName.Text)) > 0 Then
        SaveSetting "OneTime", "Settings", "UserName", _
            Trim$(txtName.Text)
    End If

    Unload Me
    MsgBox "Start the main program here"
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated