Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
How can I programmatically change the state of a check box and next tume I run application doesn't change eg.

VB
checkbox1.checked = false


will changes the state of the checkbox but next time program runs it reverts to the design time default how can I keep it changed? eg false?
Or I have to use a file with an indicator eg a txt file when going false store a var in the file and read it and change it?
Posted
Updated 5-Nov-15 4:37am
v2
Comments
Thomas Daniels 5-Nov-15 10:08am    
Is this Windows Forms, WPF, ASP.NET, ...?
Krunal Rohit 5-Nov-15 10:12am    
Yes, you need to use some storage to retain the modified value.

-KR
Sergey Alexandrovich Kryukov 5-Nov-15 10:42am    
"next time programs runs" reveal that you don't understand the basic operation of a computer system, OS, application, process, and other basic things. Please learn it all. And learn the concept of "persistence". Not all OS are like that, but almost all of them.
—SA

The best way IMHO is to use the My.Settings Object[^]

Take a look at this example: Using Settings How to use settings to preserve information between runs. [^]

Defining a Setting
Project -> Properties -> Settings

VB
Module Module1
    Sub Main()
       Console.WriteLine("Number of times run  {0} ", My.Settings.NumberOfTimesRun)
       My.Settings.NumberOfTimesRun += 1
       Console.WriteLine("Number of times run  {0} ", My.Settings.NumberOfTimesRun)
    
       ' Save the settings
        My.Settings.Save()

   End Sub
End Module    
 
Share this answer
 
v2
Please see my comment to the question.

Perhaps this is a weird way of answering such question; and I cannot sure you can understand that, but you need to start with something. The idea is: the OS you are using is not like this: https://en.wikipedia.org/wiki/Persistence_%28computer_science%29#Persistent_operating_systems[^].

You really need to learn what your OS does in general. Now, sooner or later, you will get to writing and reading persisting data. So, a big warning for you: some people try to persist data in system Registry, which is a really bad thing; there are too many applications already collecting trash in the registry, to such a great extent that the system starts stalling. My past answers explain how to get good place to store your data, in most cases:
which is better : use of registery in order to store setting or use of Settings class[^],
How to find my programs directory[^].

Some more ideas:
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/bb397750%28v=vs.110%29.aspx[^].

Sorry if big part of this information seems to be over your head. Not everything comes at once.

—SA
 
Share this answer
 

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