C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
To loop or not...? Posted by Alvas89 on 28 Feb 2009 at 12:56 PM
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?

Thamks
Report
Re: To loop or not...? Posted by secutos on 16 Mar 2009 at 4:23 PM
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.

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();
}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.