Results 1 to 10 of 10

Thread: Make a function happen ONLY ONCE on startup of Program {RESOLVED}

  1. #1

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Make a function happen ONLY ONCE on startup of Program {RESOLVED}

    Hello,

    I need to know how I could make my program have a welcome message ONLY the first time the porgram starts?

    Thank you for your help everyone!

    Stilekid007

    ____________________________
    I RATE ALL HELPFULL POSTS!
    Last edited by stilekid007; Jun 30th, 2005 at 09:50 AM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Make a function happen ONLY ONCE on startup of Program

    Well there are a lot of ways to do it but here's one. Create a global variable called bDone and then do

    VB Code:
    1. Public Sub DisplayWelcome()
    2.  
    3.     If bDone Then Exit Sub
    4.    
    5.     ' Welcome message
    6.    
    7.     bDone = True
    8.    
    9. End Sub

  3. #3
    Member Matias's Avatar
    Join Date
    Jun 2005
    Location
    Buenos Aires, Argentina.
    Posts
    43

    Re: Make a function happen ONLY ONCE on startup of Program

    Hi, u could use some api too save data in the windows registry. U could save something like "INIT_FLAG = True". When the program start u check that value and procede as needed

    If i recall correctly those api are:

    GetPrivateProfileString
    WritePrivateProfileString

    I know i'm not being very clear but is not very easy for me to write in english, i hope i could give a clue.

    bye!
    Last edited by Matias; Jul 21st, 2005 at 09:22 AM.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Make a function happen ONLY ONCE on startup of Program

    Or for simplicity... GetSetting & SaveSetting will also read & save to the registry.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Make a function happen ONLY ONCE on startup of Program

    Strange, it seems very easy to do it unless what you are talking about is to display a welcome message only after running your app for the first time when it was installed then in the succeeding time you will run your program the welcome message will not appear anymore.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Make a function happen ONLY ONCE on startup of Program

    Hello everyone! Thank you for your replys! Martin - Your code works nice for the way it was meant but what I meant (I didn't explain very well) is how DEE-U explained it.

    I need my program to

    Display a welcome message only after running your app for the first time when it was installed then in the succeeding time you will run your program the welcome message will not appear anymore
    Can this even be done?

    Thank you to everyone!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Make a function happen ONLY ONCE on startup of Program

    Then you should use techgnome's suggestion. You can look at the Use SaveSetting and GetSetting to store and retrieve data from the Registry link in my signature for an example. The example (if I remember correctly) saves the value of a textbox but you could modify it to just say "did it once already" or something like that.

  8. #8

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Make a function happen ONLY ONCE on startup of Program

    Ok, here is some code I setup.

    It makes my program display the message only the first time the proram runs after installation.

    I have a text box (INVISIBLE) and the code below.

    VB Code:
    1. Private Sub Form_Load()
    2. Text3.Text = GetSetting(App.EXEName, "Settings", "Username")
    3.  
    4. If Text3.Text = "PRELOADED" Then
    5. 'Do Nothing
    6.  
    7. Else
    8. ' Display Welcome Msg
    9. SaveSetting App.EXEName, "Settings", "Username", "PRELOADED"
    10. End If
    11. End Sub

    Thank you all and have a great day!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Make a function happen ONLY ONCE on startup of Program

    You don't need the textbox.

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim strLoaded As String
    4.  
    5. strLoaded = GetSetting(App.EXEName, "Settings", "Username")
    6.  
    7. If strLoaded = "PRELOADED" Then
    8. 'Do Nothing
    9.  
    10. Else
    11. ' Display Welcome Msg
    12. SaveSetting App.EXEName, "Settings", "Username", "PRELOADED"
    13. End If
    14. End Sub

  10. #10

    Thread Starter
    Hyperactive Member stilekid007's Avatar
    Join Date
    Apr 2005
    Location
    DUDE! I'm your neighbor! HELLO!!!
    Posts
    388

    Re: Make a function happen ONLY ONCE on startup of Program {RESOLVED}

    Hmmm... Thats nice! thank you sir!

    Have a great day!
    Stilekid007
    Quote Originally Posted by stilekid007
    I RATE ALL HELPFULL POSTS!

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