read multiple values from textbox are process them

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • smoky_flame via DotNetMonster.com

    read multiple values from textbox are process them

    hi,
    is it possible to take multiple values(int) seperated by commas as input from
    textbox in C# and draw a figure using those values.
    e.g. drawing a simple path using 1,2,3,4 values.

    --
    Message posted via http://www.dotnetmonster.com

  • Peter Duniho

    #2
    Re: read multiple values from textbox are process them

    On Sat, 15 Mar 2008 11:42:57 -0700, smoky_flame via DotNetMonster.c om
    <u42139@uwewrot e:
    hi,
    is it possible to take multiple values(int) seperated by commas as input
    from
    textbox in C# and draw a figure using those values.
    e.g. drawing a simple path using 1,2,3,4 values.
    Yes, it's possible. As long as you can clearly and precisely define the
    problem, there is a solution.

    As stated so far, though, I don't think there is one. The biggest problem
    is that "drawing a simple path using 1,2,3,4 values" is too vague. How
    are the values supposed to be interpreted with respect to describing a
    "simple path"?

    You can use String.Split() or other mechanisms to separate a single string
    that might be contained in a TextBox into individual parts, and of course
    you can then use int.TryParse() to parse those parts into numbers. But
    then what? How do you expect to use the numbers?

    Pete

    Comment

    • smoky_flame via DotNetMonster.com

      #3
      Re: read multiple values from textbox are process them

      actually im taking input in textboxes. ive done this with single vales as i
      used:
      if (TextBox4_pa.Te xt == "1")
      {
      p1.StartCap = LineCap.ArrowAn chor;
      Gfx.DrawLine(p1 ,200,140,76,80) ;

      }
      if (TextBox4_pa.Te xt == "2")
      {
      p1.StartCap = LineCap.ArrowAn chor;
      Gfx.DrawLine(p1 , 210, 140, 190, 50);

      }
      if (TextBox4_pa.Te xt == "3")
      {
      p1.StartCap = LineCap.ArrowAn chor;
      Gfx.DrawLine(p1 , 210, 140, 160, 110);

      }



      but i cant do it with values in the textbox like 1,2,3 ....any coding
      suggestions or help.?

      Jon Skeet [C# MVP] wrote:
      >is it possible to take multiple values(int) seperated by commas as input from
      >textbox in C# and draw a figure using those values.
      >e.g. drawing a simple path using 1,2,3,4 values.
      >
      >Yes, certainly. Which bit are you having trouble with? Split the job
      >into several small tasks, and focus on one at a time. If you have a
      >problem with one particular task, I suggest you ask about that task in
      >isolation.
      >
      --
      Message posted via DotNetMonster.c om
      Expert guide to Australian online pokies. Find high RTP games, safe offshore casinos, and detailed reviews to keep you informed.


      Comment

      • smoky_flame via DotNetMonster.com

        #4
        Re: read multiple values from textbox are process them

        actually im taking input in textboxes. ive done this with single vales as i
        used:
        if (TextBox4_pa.Te xt == "1")
        {
        p1.StartCap = LineCap.ArrowAn chor;
        Gfx.DrawLine(p1 ,200,140,76,80) ;

        }
        if (TextBox4_pa.Te xt == "2")
        {
        p1.StartCap = LineCap.ArrowAn chor;
        Gfx.DrawLine(p1 , 210, 140, 190, 50);

        }
        if (TextBox4_pa.Te xt == "3")
        {
        p1.StartCap = LineCap.ArrowAn chor;
        Gfx.DrawLine(p1 , 210, 140, 160, 110);

        }



        but i cant do it with values in the textbox like 1,2,3 ....any coding
        suggestions or help.?

        Jon Skeet [C# MVP] wrote:
        >is it possible to take multiple values(int) seperated by commas as input from
        >textbox in C# and draw a figure using those values.
        >e.g. drawing a simple path using 1,2,3,4 values.
        >
        >Yes, certainly. Which bit are you having trouble with? Split the job
        >into several small tasks, and focus on one at a time. If you have a
        >problem with one particular task, I suggest you ask about that task in
        >isolation.
        >
        --
        Message posted via http://www.dotnetmonster.com

        Comment

        • smoky_flame via DotNetMonster.com

          #5
          Re: read multiple values from textbox are process them

          actually im taking input in textboxes. ive done this with single vales as i
          used:
          if (TextBox4_pa.Te xt == "1")
          {
          p1.StartCap = LineCap.ArrowAn chor;
          Gfx.DrawLine(p1 ,200,140,76,80) ;

          }
          if (TextBox4_pa.Te xt == "2")
          {
          p1.StartCap = LineCap.ArrowAn chor;
          Gfx.DrawLine(p1 , 210, 140, 190, 50);

          }
          if (TextBox4_pa.Te xt == "3")
          {
          p1.StartCap = LineCap.ArrowAn chor;
          Gfx.DrawLine(p1 , 210, 140, 160, 110);

          }



          but i cant do it with values in the textbox like 1,2,3 ....any coding
          suggestions or help.?

          Jon Skeet [C# MVP] wrote:
          >is it possible to take multiple values(int) seperated by commas as input from
          >textbox in C# and draw a figure using those values.
          >e.g. drawing a simple path using 1,2,3,4 values.
          >
          >Yes, certainly. Which bit are you having trouble with? Split the job
          >into several small tasks, and focus on one at a time. If you have a
          >problem with one particular task, I suggest you ask about that task in
          >isolation.
          >
          --
          Message posted via DotNetMonster.c om
          Expert guide to Australian online pokies. Find high RTP games, safe offshore casinos, and detailed reviews to keep you informed.


          Comment

          • smoky_flame via DotNetMonster.com

            #6
            Re: read multiple values from textbox are process them

            im going to do what u said. kindly make me clear he 5th point.

            Jon Skeet [C# MVP] wrote:
            >actually im taking input in textboxes. ive done this with single vales as i
            >used:
            >[quoted text clipped - 19 lines]
            >but i cant do it with values in the textbox like 1,2,3 ....any coding
            >suggestions or help.?
            >
            >Well, the way I would split the job up is:
            >
            >1) Obtaining the text from the TextBox (use the Text property)
            >2) Split the string by commas (use String.Split)
            >3) Potentially trim each string (use String.Trim)
            >4) Parse each string (use int.TryParse)
            >5) Handle each integer (I suspect you should aim for more general
            code than the above, e.g. a map or array from number to line
            points)
            >
            --
            Message posted via DotNetMonster.c om
            Expert guide to Australian online pokies. Find high RTP games, safe offshore casinos, and detailed reviews to keep you informed.


            Comment

            • smoky_flame via DotNetMonster.com

              #7
              Re: read multiple values from textbox are process them

              ive used string.split and it delimited th commas.
              but how can i used GDI+ with it?
              Jon Skeet [C# MVP] wrote:
              >im going to do what u said. kindly make me clear he 5th point.
              >
              >Well, your previously posted code has several "if" blocks, with the
              >same code in each apart from some different numbers.
              >
              >Encapsulate those numbers in a type, and then you can have an array (or
              >a Dictionary<int, YourNewType>) so that you don't need if/else - just
              >use the parsed number to get at the set of numbers directly.
              >
              --
              Message posted via DotNetMonster.c om
              Expert guide to Australian online pokies. Find high RTP games, safe offshore casinos, and detailed reviews to keep you informed.


              Comment

              • Peter Duniho

                #8
                Re: read multiple values from textbox are process them

                On Sun, 16 Mar 2008 00:20:41 -0700, smoky_flame via DotNetMonster.c om
                <u42139@uwewrot e:
                im going to do what u said. kindly make me clear he 5th point.
                As an example of one possible implementation of "the 5th point":

                Instead of all those if() statements you posted in previous code, you
                could encapsulate that information as an array:

                Point[][] pointPairs = { { new Point(0, 0), new Point(200, 140) },
                { new Point(200, 140), new Point(76, 80) },
                { new Point(210, 140), new Point(190, 50) },
                { new Point(210, 140), new Point(160, 110)}
                };

                Then you can draw the lines like this:

                int ipair;

                if (int.TryParse(T extBox4_pa.Text , out ipair))
                {
                Point[] pointPair = pointPairs[ipair];

                p1.StartCap = LineCap.ArrowAn chor;
                Gfx.DrawLine(p1 , pointPair[0], pointPair[1]);
                }
                else
                {
                // handle error
                }

                Of course, in your actual code you'd also incorporate the splitting
                technique described, presumably in a loop where you process all of the
                resulting strings.

                Pete

                Comment

                • Martin Bonner

                  #9
                  Re: read multiple values from textbox are process them

                  On Mar 15, 7:14 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
                  wrote:
                  On Sat, 15 Mar 2008 11:42:57 -0700, smoky_flame via DotNetMonster.c om
                  >
                  <u42139@uwewrot e:
                  hi,
                  is it possible to take multiple values(int) seperated by commas as input
                  from textbox in C# and draw a figure using those values.
                  e.g. drawing a simple path using 1,2,3,4 values.
                  >
                  Yes, it's possible.
                  Agreed
                  As long as you can clearly and precisely define the
                  problem, there is a solution.
                  Not necessarily. Counter example: "Specify an algorithm to decide if
                  an arbitrary Turing machine will halt".

                  .... however, I agree that the OP's main problem is a lack of clarity
                  in the specification rather than a fundamentally insoluble problem.

                  Comment

                  Working...