Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

To loop or not...?

Alvas89Alvas89 Posts: 1Member
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

Comments

  • secutossecutos Posts: 10Member
    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]
Sign In or Register to comment.