I am making my application as exe file.. In my project i am using setting variable to count the number of times the applications opened.. if the user opens the application more than 5 times i want to restrict the user from opening the application again. for that i am using the following coding in form shown
Private Sub T01SaleBill_Shown(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Shown
if my.settings.openedtimes >5 then
me.close()
else
my.settings.openedtimes += 1;
my.settings.save()
end if;
End Sub
the exe file created and it works fine through my exe..after the application opened 5 times.. the form closed.. now i reset the my.settings.openedtimes as 0 and again create a new exe. now i uninstall previous exe.. and run the new exe. this times also my form closed. i think the setting variable my.settings.openedtimes holds value greater than 5 as previous. i can't understand what is the problem with this settings variable.. can anyone help me what's the problem here..
Add a boolean setting named newvers and set it to true in the settings designer. Then try this
Private Sub Form1_Shown(sender As Object, _
e As EventArgs) Handles Me.Shown
If My.Settings.newvers Then
My.Settings.Upgrade() 'get previous values
'change values that should not be carried over
My.Settings.openedtimes = 1
My.Settings.newvers = False 'turn new version off
Else
My.Settings.openedtimes += 1
End If
If My.Settings.openedtimes > 5 Then Me.Close()
My.Settings.Save()
End Sub