Results 1 to 14 of 14

Thread: [RESOLVED] How to make the form appear during first time running the program

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] How to make the form appear during first time running the program

    How to make the form appear during first time running the program?

    I have form 1 and form 2. If the first time the program are running after installation, the form1 will appear..

    Next time, the program it run, the form1 no more appear.. it directly show form2..

    How to do that?

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to make the form appear during first time running the program

    Store the fact that it was already run somewhere, e.g. save to registry, or save to a text file, and so on. Every program run read from registry, or check if text file exists, etc and show form1 accordingly.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to make the form appear during first time running the program

    ha


    How to start it? any sample to do like this?

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to make the form appear during first time running the program

    Here's an example using the Registry:
    Code:
    Private Sub Form_Load()
    Dim strRun As String
    Me.Visible = False
    strRun = GetSetting(App.EXEName, "RunStatus", "HasRun", "False")
    If strRun = "False" Then
        SaveSetting App.EXEName, "RunStatus", "HasRun", "True"
        Me.Visible = True
    Else
        Form2.Show
        Unload Me
    End If
    End Sub
    When first run, Form1 will be displayed and insert a new Key and value, (HasRun and "True") in the Registry, under
    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<name of your application>\RunStatus

    Next time it runs that key will exist so Form2 is shown and Form1 unloads.
    You may wish to put this in Form2 during testing so you can unset the registry key
    Code:
    Private Sub Command1_Click()
    SaveSetting App.EXEName, "RunStatus", "HasRun", "False"
    End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to make the form appear during first time running the program

    Ok, I want to start this first..

    Where should I put this code? In form 1 or in form 2?

    Private Sub Form_Load()
    Dim strRun As String
    Me.Visible = False
    strRun = GetSetting(App.EXEName, "RunStatus", "HasRun", "False")
    If strRun = "False" Then
    SaveSetting App.EXEName, "RunStatus", "HasRun", "True"
    Me.Visible = True
    Else
    Form2.Show
    Unload Me
    End If
    End Sub


    When first run, Form1 will be displayed and insert a new Key and value, (HasRun and "True") in the Registry, under
    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<name of your application>\RunStatus
    Can I use default location? I don't know where the key value was inserted?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make the form appear during first time running the program

    If Form1 is your startup form, VB will ALWAYS load it first. What you need to do is prevent it from showing, and call Form2, so that code would go in Form1.

  7. #7
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to make the form appear during first time running the program

    Quote Originally Posted by matrik02
    Can I use default location? I don't know where the key value was inserted?
    I told you where the key is:

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<name of your application>\RunStatus

    So if your Application name was Project1 then the key would be found here:

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Project1\RunStatus

    Using GetSetting and SaveSetting the 'Default' Value' is

    HKEY_CURRENT_USER\Software\VB and VBA Program Settings\

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

    Re: How to make the form appear during first time running the program

    The simplest and best thing to do is this.

    Code:
    Public Sub Main()
    
    Dim strRun As String
    
    strRun = GetSetting(App.EXEName, "RunStatus", "HasRun", "False")
    If strRun = "False" Then
        SaveSetting App.EXEName, "RunStatus", "HasRun", "True"
        Form1.Show
    Else
        Form2.Show
    End If
    
    End Sub
    To implement this solution you need to add a code module to your application and paste the above code into it. Then go to Project|Properties and change the Startup Object to Sub Main. Problem solved.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to make the form appear during first time running the program

    Greet, it works.Now I narrow down it.


    Form 1 is my start up


    here is the code in my form1.. I want do like this, if the condition true, then the form 2 appear and form 1 will not appear during the start up. It will go to the form2..

    But if the condition is false, then form1 always appear during start up






    If Check1.Value = vbChecked And Check3.Value = vbChecked Then ' If true, then this form1 not show during first time
    Unload Me
    Form2.Show
    ElseIf Check2.Value = vbChecked And Check4.Value = vbChecked Then ' If false, then this form1 will show again during first time

    Unload Me
    Formcancel.Show
    end if


  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to make the form appear during first time running the program

    Quote Originally Posted by MartinLiss
    The simplest and best thing to do is this.

    Code:
    Public Sub Main()
    
    Dim strRun As String
    
    strRun = GetSetting(App.EXEName, "RunStatus", "HasRun", "False")
    If strRun = "False" Then
        SaveSetting App.EXEName, "RunStatus", "HasRun", "True"
        Form1.Show
    Else
        Form2.Show
    End If
    
    End Sub
    To implement this solution you need to add a code module to your application and paste the above code into it. Then go to Project|Properties and change the Startup Object to Sub Main. Problem solved.
    I have try this code, it work..

    At first I run this code, the form 1 appear.
    when I click the cancel button in form1, the form1 unload. When I start again, the form2 appear.

    I aspect that if the program first running the form1 will be appear if i click the cancel button on cancel button but this not work. How to to do that?

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make the form appear during first time running the program

    Quote Originally Posted by matrik02
    At first I run this code, the form 1 appear.
    when I click the cancel button in form1, the form1 unload. When I start again, the form2 appear.
    In your cancel button, delete the registry entry that was made in Sub Main.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to make the form appear during first time running the program

    Ah, i got the idea

    What is the default value for HasRun ? True or False?
    Last edited by matrik02; Apr 21st, 2008 at 10:36 AM.

  13. #13
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: How to make the form appear during first time running the program

    Click the Start button and then the Run option. In the Open box type in Regedit and click OK. This will open the Registry Editor. Be careful in there if you don't know what you are doing. Deleting the wrong things could leave you with an unusable machine.

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] How to make the form appear during first time running the program

    For the first run, the default should be True.

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