I'm looking to load a value contained in a .txt file into a numeric up-down. I've been loading text from .txts into combo boxes using this:
//Load Movelist
if (comboBox_PlayerChar.SelectedIndex == 27 && gameno == 3)
{
charno = 27;
this.comboBox_Movelist.Items.Clear();
StreamReader movelist = new StreamReader(@"filepath\document.txt");
string line = movelist.ReadLine();
while (line != null)
{
comboBox_Movelist.Items.Add(line);
line = movelist.ReadLine();
}
}
I'd imagine it'd be a similar method for numericUpDowns, but I'm honestly clueless as of what to do. I've done some snooping around the internet and no one else seems to want to do the same.
tl;dr, I need some way to take a single number that's in a text file, write it to a variable and set the numericUpDown to that variable.
The important part is getting the value into a variable. setting the actual numericUpDown is easy.
Hopefully you understand what I mean.
If its a single number value in a text file
using (StreamReader sr = new StreamReader(@"filepath\document.txt"))
{
// read the first line
string line = sr.ReadLine();
// parse the line for an integer
int value;
int.TryParse(line, out value);
// if the line in the file was indeed an integer, the variable value will be equal to it now
// sr will be disposed at end of using block
}