Answered by:
First Time Run Form

Question
-
Hey Again,
How do i make a form show when a user uses my application for the first time and only shows that time.
Thanks Luke Arran
Sunday, April 10, 2011 7:43 PM
Answers
-
You can use the registry for that
Imports Microsoft.Win32 Public Class Form1 'VB2010 SP1 style code, byval is not needed anymore Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim keyName As String = "HKEY_CURRENT_USER\SampleCreateForm" Dim rk As RegistryKey = Registry.Users Dim registeredString As Object = Registry.GetValue(keyName, "FirstTimeForm", "") If registeredString Is Nothing OrElse registeredString.ToString = "" Then registeredString = "Luke" Registry.SetValue(keyName, "FirstTimeForm", registeredString) Dim frm2 As New FirstTimeForm frm2.ShowDialog() End If End Sub End Class
Success
Cor- Proposed as answer by John Anthony Oliver Monday, April 11, 2011 11:44 PM
- Marked as answer by Kee Poppy Friday, April 15, 2011 9:58 AM
Monday, April 11, 2011 6:34 AM -
Use a settings variable.
In Project \ Properties \ Settings add a new setting of type boolean with name FirstTime and User scope and a default value of True.
In the form load event for the main form, use code like this:
If My.Settings.FirstTime then
'Do your first time code here
My.Settings.FirstTime = False
End ifYour first time code that would show a form could be:
Dim frm as FirstForm = New FirstForm
frm.ShowDialogFor testing, use the Synchronize button on the Settings page to restore your FirstTime time setting to True.
- Proposed as answer by John Anthony Oliver Monday, April 11, 2011 11:44 PM
- Marked as answer by Kee Poppy Friday, April 15, 2011 10:02 AM
Monday, April 11, 2011 1:35 AM
All replies
-
Hi Luke Arran,
Try this idea please.
Show a message or a FORM if a file does NOT exist, at the same time create that file so the message or Form is not shown again. :-)
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If System.IO.File.Exists(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\firstRun.txt") = False Then My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\firstRun.txt", "Hi there!!", False) MessageBox.Show("Hello and welcome to the first time run of my new application...") End If End Sub End Class
See also:>>
How to make my app only do something the first time that it's run
Make a form appear only on first run?
Regards,
John
Click this link to see how to insert a picture into a forum post.
Installing VB6 on Windows 7
Monday, April 11, 2011 12:51 AM -
Use a settings variable.
In Project \ Properties \ Settings add a new setting of type boolean with name FirstTime and User scope and a default value of True.
In the form load event for the main form, use code like this:
If My.Settings.FirstTime then
'Do your first time code here
My.Settings.FirstTime = False
End ifYour first time code that would show a form could be:
Dim frm as FirstForm = New FirstForm
frm.ShowDialogFor testing, use the Synchronize button on the Settings page to restore your FirstTime time setting to True.
- Proposed as answer by John Anthony Oliver Monday, April 11, 2011 11:44 PM
- Marked as answer by Kee Poppy Friday, April 15, 2011 10:02 AM
Monday, April 11, 2011 1:35 AM -
You can use the registry for that
Imports Microsoft.Win32 Public Class Form1 'VB2010 SP1 style code, byval is not needed anymore Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim keyName As String = "HKEY_CURRENT_USER\SampleCreateForm" Dim rk As RegistryKey = Registry.Users Dim registeredString As Object = Registry.GetValue(keyName, "FirstTimeForm", "") If registeredString Is Nothing OrElse registeredString.ToString = "" Then registeredString = "Luke" Registry.SetValue(keyName, "FirstTimeForm", registeredString) Dim frm2 As New FirstTimeForm frm2.ShowDialog() End If End Sub End Class
Success
Cor- Proposed as answer by John Anthony Oliver Monday, April 11, 2011 11:44 PM
- Marked as answer by Kee Poppy Friday, April 15, 2011 9:58 AM
Monday, April 11, 2011 6:34 AM -
You can use the registry for that
Imports Microsoft.Win32 Public Class Form1 'VB2010 SP1 style code, byval is not needed anymore Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim keyName As String = "HKEY_CURRENT_USER\SampleCreateForm" Dim rk As RegistryKey = Registry.Users Dim registeredString As Object = Registry.GetValue(keyName, "FirstTimeForm", "") If registeredString Is Nothing OrElse registeredString.ToString = "" Then registeredString = "Luke" Registry.SetValue(keyName, "FirstTimeForm", registeredString) Dim frm2 As New FirstTimeForm frm2.ShowDialog() End If End Sub End Class
Success
Cor
Thanks for your replies,
Cor that code worked fine thanks alot.
Monday, April 11, 2011 4:31 PM