Binary File IO

  • Thread starter Thread starter bernden
  • Start date Start date
B

bernden

A C# program that I am currently working on contains about 100
textBoxes, 5 pictureBoxes, 20+ radioButtons ect.

Concern / Question 1 (Save File)
In the past when writing code to save the currently opened file, I would
create about 125+ variables to save the text, images and radioButton
checkstate to disk. These same variables would be used to load
everything back into their correct control when the file was re-opened.
Does anyone know if there is a faster / better way to accomplish the
same thing ?

Concern / Question 2 (Close File)
When a user clicks on the 'Close File' menu option in the above program,
code is used to clear / re-set all user data from the controls. The
user's screen looks the same as when it was first opened... but, all the
program variables used to store data and perform the necessary
calculations still contain their data. How can I clear them or at least
make sure that they do not cause problems when the user begins to enter
new data and tries t o perform a new set of calculations.

Any help would be appreciated.

bernden
 
Hi,

Concern / Question 1 (Save File)
In the past when writing code to save the currently opened file, I would
create about 125+ variables to save the text, images and radioButton
checkstate to disk. These same variables would be used to load
everything back into their correct control when the file was re-opened.
Does anyone know if there is a faster / better way to accomplish the
same thing ?

Why you create so many variables?
You can iterate in the controls and get theirs properties (the one you are
going to store) directly from them, no need to create new variables

Are the number of controls constant? if so you know beforehand how many you
need to read from the file, otherwise yuo need to store this info too in the
file

The
user's screen looks the same as when it was first opened... but, all the
program variables used to store data and perform the necessary
calculations still contain their data. How can I clear them or at least
make sure that they do not cause problems when the user begins to enter
new data and tries t o perform a new set of calculations.

You need to store somewhere the seeds , any value you are going to use in
the calculations that will not vary.


cheers,
 
Create a class object to store the different settings for your form. Create
methods to "bind" the data to the form, and then another to "bind" the input
values to the class object. Serialize/Deserialize the class object to save
the headache of doing it manually (also less error prone, it seems to me).

I'll let someone else inform you that that many controls on a form is
probably a bad idea, difficult design, etc. Someone else might propose a
"wizard" or something.

Scott
 
Thank you for the reply.

My experience with iteration is limited to counting, enabling and
clearing controls. I have never tried to iterate thru the controls on a
Form and get the properties of just the ones that need to be stored.

Is there a site that provides a tutorial on how to accomplish this ?

bernden
 
Back
Top