Hi there! I am stuck and looking for help. I have a text box in which I ask the user up to what number he/she would like to start, end the count in the range of 1 to 100. If the input is 3,25 or 7,12,52 how would I implement the loop?
I'm still having a little difficulty understanding your question but I'll answer it to the best of my ability.
You have a TextBox control on a windows form. The user types in "3,25" into the textbox. You want 3 to be your starting number and you want to look until 25 (the end count).
If your user types "7,12,52" into the textbox, this is not a valid input because you have an extra number. So tell your user he made a mistake and to try again.
[code] string Input = textBox1.Text; string[] Splitted = Input.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries); if (Splitted.Length == 2) { int Start = Int32.Parse(Splitted[0]); int End = Int32.Parse(Splitted[1]); for (int i = Start; i < End; i++) { // do stuff in this loop } } else { MessageBox.Show("You can only have 2 numbers in the textbox separated by one comma. Please try again.", "Get it right"); // Computer.CallBSOD(); } [/code]
Comments
You have a TextBox control on a windows form. The user types in "3,25" into the textbox. You want 3 to be your starting number and you want to look until 25 (the end count).
If your user types "7,12,52" into the textbox, this is not a valid input because you have an extra number. So tell your user he made a mistake and to try again.
[code]
string Input = textBox1.Text;
string[] Splitted = Input.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
if (Splitted.Length == 2)
{
int Start = Int32.Parse(Splitted[0]);
int End = Int32.Parse(Splitted[1]);
for (int i = Start; i < End; i++)
{
// do stuff in this loop
}
}
else
{
MessageBox.Show("You can only have 2 numbers in the textbox separated by one comma. Please try again.", "Get it right");
// Computer.CallBSOD();
}
[/code]