Hi, basically all I want to do is code my project so that it stores any saved variables for the next time the program is run. At the moment once I close and reopen the program it obviously resets any variables. Is there any simple way to do this (please bear in mind, im very new at programming)
Il give you an example. If I have a simple program that when I press a button it adds 1 to a counter. Now next time I open that program and press the button again I want to add to the previous counter.
Thanks in advance
How can I save a variable even after the program is exited?
Started by lucasmeister, Aug 11 2010 04:01 AM
8 replies to this topic
#1
Posted 11 August 2010 - 04:01 AM
|
|
|
#2
Posted 11 August 2010 - 05:06 AM
you need to save that value somewhere. Like a file, or the windows registry.
#3
Posted 11 August 2010 - 05:47 AM
You can save the varible during the Form_Closing event.
I haven't used databases or anything like that yet, but txt files can work as save files.
I haven't used databases or anything like that yet, but txt files can work as save files.
#4
Posted 11 August 2010 - 06:06 AM
#5
Posted 11 August 2010 - 07:33 AM
killcode said:
Lol, you asked this at dreamincode.
You only know because you google'd for an answer to put here. ;)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 11 August 2010 - 08:54 AM
#7
Posted 11 August 2010 - 01:29 PM
You can save the value of a variable in a text or xml file. When you reopen the program, it will get those values again from those files.
#8
Posted 11 August 2010 - 08:54 PM
Well windows application? then you can save the values in settings file. Have a walkthrough on how to create a settings file from the coding for fun
http://blogs.msdn.com/b/coding4fun/archive/2009/06/23/9709252.aspx
#9
Posted 22 August 2010 - 06:55 AM
Save it in app.config.
First you click on project name with right button in project explorer,go to properties -> settings.
You make your fields here,and set scope on User.
then in your code u can read the value with :
and you can write with :
First you click on project name with right button in project explorer,go to properties -> settings.
You make your fields here,and set scope on User.
then in your code u can read the value with :
double theValue = Program_Name.Properties.Settings.Default.thevaluename;
and you can write with :
Program_Name.Properties.Settings.Default.thevaluename = theValue; Program_Name.Properties.Settings.Default.Save();
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










