[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?
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.
Re: How to make the form appear during first time running the program
ha:confused:
How to start it? any sample to do like this?
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
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?
Quote:
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
Quote:
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?
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.
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\
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.
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
Quote:
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
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?
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.
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?
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.
Re: [RESOLVED] How to make the form appear during first time running the program
For the first run, the default should be True.