Question:
Saving state in my application?
2009-11-03 15:34:16 UTC
Im building a computer application, and I have to save the state of the application, so that when the file is opened again by the user, all the objects are still in the same place where they left them.

i want to know, how i can implement this.

Thanks
Three answers:
2009-11-03 16:03:20 UTC
You would just store the data in a file, C++ is popular so here's an example in it. If you plan on using C++, google "fstream C++" that will return any answer you could ever reasonably have.



#include

#include

void Store_Variables()

{

int Variable_To_Be_Stored;

int Variable_To_Be_Stored = 9;

int Variable_To_Retrieve;

std::string path;

path = "C:\Variable Storage.ini";

std::fstream Storage_File;

Storage_File = (path.c_str());

// This stores a variable.

Storage_File << Variable_To_Be_Stored;

// This retrieves a variable.

Storage_File >> Variable_To_Retrieve;

return 0;

}
NeoJoe
2009-11-03 16:05:29 UTC
Are you using Visual Studio 2008? If so, it's VERY simple to do.



All you do is use "My.Settings" and you can set whether it's a string/boolean or something in the project's properties. No modules or extra code required.



Example:

Sub FormLoad() 'Load the settings

TextBox1.Text = My.Settings.TextBox1Contents 'Or whatever you want the name(s) to be



Sub FormClose() 'Save the settings

My.Settings.TextBox1Contents = TextBox1.Text
2009-11-03 15:39:51 UTC
At the point where you want to save your state information, you save it into a file.



At the point where the program should restore state you check for the file, read it and restore your objects.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...