|
-
Apr 17th, 2008, 12:44 AM
#1
Thread Starter
Frenzied Member
[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?
-
Apr 17th, 2008, 12:58 AM
#2
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.
-
Apr 17th, 2008, 01:00 AM
#3
Thread Starter
Frenzied Member
Re: How to make the form appear during first time running the program
ha
How to start it? any sample to do like this?
-
Apr 17th, 2008, 01:27 AM
#4
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
-
Apr 17th, 2008, 05:32 AM
#5
Thread Starter
Frenzied Member
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?
-
Apr 17th, 2008, 06:34 AM
#6
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.
-
Apr 18th, 2008, 05:28 AM
#7
Re: How to make the form appear during first time running the program
 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\
-
Apr 18th, 2008, 10:10 AM
#8
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.
-
Apr 19th, 2008, 01:40 AM
#9
Thread Starter
Frenzied Member
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
-
Apr 21st, 2008, 07:11 AM
#10
Thread Starter
Frenzied Member
Re: How to make the form appear during first time running the program
 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?
-
Apr 21st, 2008, 09:14 AM
#11
Re: How to make the form appear during first time running the program
 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.
-
Apr 21st, 2008, 10:02 AM
#12
Thread Starter
Frenzied Member
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.
-
Apr 21st, 2008, 10:35 AM
#13
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.
-
Apr 21st, 2008, 11:32 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|