M
Marge Inoferror
Visual C#...
I'd like to save some settings that are in integers and then save some lists
of file names. I'm just starting off (as you can tell - no doubt.).
I'm starting by trying to save two integers: numRows and numCols.
I put a saveFileDialog in my design view. When it's clicked I do this:
private void clickSaveFile(object sender, System.EventArgs e)
{
DialogResult buttonClicked = saveFileDialog.ShowDialog();
DialogResult buttonClicked = saveFileDialog.ShowDialog();
if (buttonClicked.Equals(DialogResult.OK))
{
Stream saveStream =saveFileDialog.OpenFile();
StreamWriter saveWriter = new StreamWriter(saveStream);
saveWriter.Write(numRows);
saveWriter.Write(numCols);
saveWriter.Close();
}
}
This converts the integers to strings, I believe.
I try to retrieve the file:
private void clickFileOpen(object sender, System.EventArgs e)
{
string numRowsString;
string numColsString;
DialogResult buttonClicked = openFileDialog.ShowDialog();
if (buttonClicked.Equals(DialogResult.OK))
{
Stream openStream =openFileDialog.OpenFile();
StreamReader openReader = new StreamReader(openStream);
numRowsString = openReader.ReadLine();
numColsString = openReader.ReadLine();
openReader.Close();
/* now what ?? */
}
}
How do I convert the strings to ints? Is there a better way to save and
retrive the file?
Thanks,
Marge
I'd like to save some settings that are in integers and then save some lists
of file names. I'm just starting off (as you can tell - no doubt.).
I'm starting by trying to save two integers: numRows and numCols.
I put a saveFileDialog in my design view. When it's clicked I do this:
private void clickSaveFile(object sender, System.EventArgs e)
{
DialogResult buttonClicked = saveFileDialog.ShowDialog();
DialogResult buttonClicked = saveFileDialog.ShowDialog();
if (buttonClicked.Equals(DialogResult.OK))
{
Stream saveStream =saveFileDialog.OpenFile();
StreamWriter saveWriter = new StreamWriter(saveStream);
saveWriter.Write(numRows);
saveWriter.Write(numCols);
saveWriter.Close();
}
}
This converts the integers to strings, I believe.
I try to retrieve the file:
private void clickFileOpen(object sender, System.EventArgs e)
{
string numRowsString;
string numColsString;
DialogResult buttonClicked = openFileDialog.ShowDialog();
if (buttonClicked.Equals(DialogResult.OK))
{
Stream openStream =openFileDialog.OpenFile();
StreamReader openReader = new StreamReader(openStream);
numRowsString = openReader.ReadLine();
numColsString = openReader.ReadLine();
openReader.Close();
/* now what ?? */
}
}
How do I convert the strings to ints? Is there a better way to save and
retrive the file?
Thanks,
Marge