Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In vb.net I created a variable myturn using following steps

*project
*project properties
*setting


initial value of that variable was 0
in my form i wrote following code

VB
My.Settings.myturn = My.Settings.myturn + 1
if My.Settings.myturn > 4 then
   MsgBox("you can not execute this more than this")
   end
End if

this is working nice after execution of 4 times it stops

but my problem is that i want to start it again from 0

but it is not doing and and it shows "you can not execute this more than this" again and again

What I have tried:

I thought i will go for my.settings.reset()
but my question is how to do this manually
Posted
Updated 11-Jan-19 3:11am
v2
Comments
Maciej Los 10-Jan-19 2:57am    
What happens when you close app and start your exe again?
Does the message is displayed again?
CodeMine 10-Jan-19 22:18pm    
yes dear
Sinisa Hajnal 10-Jan-19 6:09am    
Why not reset the value after the message, but before calling end?
CodeMine 10-Jan-19 22:20pm    
But I want to do it manually in vb.net environment

1 solution

You probably can't see the Settings file in the Visual Studio project.

You could click on "Show All Files" when your project is highlighted in Solution Explorer. You can then edit the value by double-clicking on the Settings.settings (or App.config - I forget which) component.

Alternatively, you could right-click on your project and choose "Properties" - you can then edit the value(s) in the Settings tab of that dialog.

If you want to edit the file using a text editor then it should be located in the same folder as your executable (debug or release folder as appropriate). Note that it will have the same name as your executable as it is renamed on build. If it is not there then have a look at the appdata folder.

There is a (quite old now) article here on CodeProject that might help Application settings in VB.NET 2.0 and Visual Studio 2005[^] - the principles still apply (from .NET 2.0 onwards)

Of course, you could as suggested, use
VB
My.Settings.myturn = 0
just before exiting the program(not just after displaying the message)
 
Share this answer
 
v2
Comments
CodeMine 12-Jan-19 2:04am    
As given in my question. let say i want to execute a vb application only 4 times.
in setting tab i will declare this "myturn" variable and initital value will be 1 and in my
application i will write

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Settings.myturn= My.Settings.myturn+ 1
If My.Settings.myturn> 4 Then
MsgBox(" Sorry no more exection")
End
End If
End Sub

in this case if you run it will run the form only for 4 times after that it will not run again.
but dear my question is that
how to start it again
it the variable will be initialized to 1 then i can test it again to see it is running for 4 times or not
so how to reinitialize this to 1
CHill60 12-Jan-19 7:31am    
I've given you two alternatives in my answer... edit the file that contains the myturn value OR reset it in code. What else do you think you need?
CodeMine 14-Jan-19 2:12am    
i did but it is not doing it is showing the initial value as 1. but if i run it is not doing. i thing somewhere its final value is stored and that has to be reset.
CHill60 14-Jan-19 8:18am    
Yes. And you can reset it by editing the Settings file using a text editor. Or you can reset it by putting some code in to reset it. That is what I have explained how to do in my Solution. Explain how you are resetting it and exactly what the results are.
CodeMine 14-Jan-19 23:26pm    
my problem is solved
i created another form and in that i wrote following code
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Settings.Reset()
End Sub
and made the form2 as startup form
executed it
again made form1 as startup form
and
executed it
it started from its initial value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900