This is basically what y'all know. However since someone asked this question I'm going to do a quick tutorial about it.
We want to get the number of times our program has been started.
Like on 1st program startup you get a messagebox and on further program startups you won't.
There are a lot of differernt ways, but I'm going to show you two ways:
My.Settings and SaveSettings(Registry)
Let us start =D
Start a new project as usually...
My.Settings
Go into your Solution-Explorer > Righ***1ck on your project > Properties
Now, click on "Settings" and simply edit the first line and use an Integer, hit enter afterwards. Name it to whatever you want, I named it "starts"
Now, we can actually use this integer.
Doubleclick on your Form so you will see the source code:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
On program startup(Form1_Load) we want to read the current starts and add 1 since it recently has been started.
We declare an Integer adove form_load to read the setting.
Code:
Public Class Form1
Dim i as integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Moving on, we will now read the setting.
Code:
i = My.Settings.starts
Now, i contains the current program startups.
Adding 1 to the current startups.
Saving the settings
Code:
My.Settings.starts = i
My.Settings.Save
My.Settings.Reload
Obviously self-explaining.
What you can do is:
Code:
If i = 1 Then
Msgbox("This is the first time you started this program")
End if
All in all it is..
Code:
Public Class Form1
Dim i as integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = my.settings.starts
If i = 1 Then
Msgbox("This is the first time you started this program")
End if
i += 1
My.Settings.starts = i
My.Settings.Save
My.Settings.Reload
End Sub
End Class
However, if you know move your .exe to another path the settings will reset. To avoid this, we can use the registry.
SaveSettings(Registry)
Code:
GetSetting(appname as string, section as string, key as string, settings as string )
SaveSetting(appname as string, section as string, key as string, settings as string )
->
Code:
Public Class Form1
Dim i as integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = GetSetting(Application.ProductName, "Settings", "Startups", i)
If i = 1 Then
Msgbox("whatever")
End if
i += 1
SaveSetting(Application.ProductName, "Settings", "Startups", i)
End Sub
End Class
You may also use a streamwriter/reader but this is the worst way IMO
Enjoy =D