View Full Version : Open, Save in VB
I need to know how to save and retrieve a game program mid-game. I have 3 books here, but can't seem to make heads or tails of programming the save/open click events.
Paul Komski
10-26-2002, 09:11 PM
More info needed to get a better idea of what you are hoping to accomplish.
The Save and Open Methods could be run from many Events, (including a Click event, which is the commonly one used from a Command Button for example).
As far as the Open Method is concerned it depends on what it is you are trying to open; a form, a report, an application, etc).
Similarly the Save Method could apply to a number of different things.
Without any knowledge of the game concerned, it sounds like you want to save the "point you have reached in the game". One can only guess that when the game is started it sets up a default "profile" from settings saved in a file or database somewhere. In such a scenario you would need to be able to save the current data to the same or an equivalent file and then have the capability of loading these specific settings by default or by making a choice from a set of options.
Yep. I'm a beginner here. I have written a tic tac toe game and we are supposed to be able to save it. I need to write it to a text file and be able to retrieve it using a common dialog box. I have the menu with the File open/ save. The dialog box looks easy enough (I've only read about it so far), but I wasn't understanding the text file. The book says to write the code in the Form Load but if I want to save half way through the game, why would the code go in Form Load? That didn't make sense to me. Thanks for your help.
Paul Komski
10-27-2002, 05:07 PM
There are some subtle differences between using the Open and Load events for a form. Open comes first and sets up the Controls and so on. The Load event is generally the best event to use for writing "setup code" for the form's initial values or procedures (if these have not been able to have been set from default values or by other code that opened the form in the first place).
The text file is obviously your "database". On loading, the values in it (be they defaults or the ones that you have saved to it previously) need to be read into the game's display; I guess that is what you would need to write for the Load event.
I imagine you are going to also have to write your own custom save event for something like a command button, which will read the current values into your textfile-database; waiting there until the form is next loaded. Using the default Save Command from a menu-item would also have to be configured/encoded to point and save the relevant values to your database - which could be anywhere on your hard-drive.
Another possibility is to write a Close event which copies the current values into new default values for the controls; thus if you ever close the form it should next reopen with the new default values that you set when the form was closed.
vBulletin v3.6.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.