read multiple values from textbox are process them

  • Thread starter Thread starter smoky_flame via DotNetMonster.com
  • Start date Start date
S

smoky_flame via DotNetMonster.com

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.
 
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
 
smoky_flame via DotNetMonster.com said:
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.
 
actually im taking input in textboxes. ive done this with single vales as i
used:
if (TextBox4_pa.Text == "1")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1,200,140,76,80);

}
if (TextBox4_pa.Text == "2")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1, 210, 140, 190, 50);

}
if (TextBox4_pa.Text == "3")
{
p1.StartCap = LineCap.ArrowAnchor;
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.?
 
actually im taking input in textboxes. ive done this with single vales as i
used:
if (TextBox4_pa.Text == "1")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1,200,140,76,80);

}
if (TextBox4_pa.Text == "2")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1, 210, 140, 190, 50);

}
if (TextBox4_pa.Text == "3")
{
p1.StartCap = LineCap.ArrowAnchor;
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.?
 
actually im taking input in textboxes. ive done this with single vales as i
used:
if (TextBox4_pa.Text == "1")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1,200,140,76,80);

}
if (TextBox4_pa.Text == "2")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1, 210, 140, 190, 50);

}
if (TextBox4_pa.Text == "3")
{
p1.StartCap = LineCap.ArrowAnchor;
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.?
 
smoky_flame via DotNetMonster.com said:
actually im taking input in textboxes. ive done this with single vales as i
used:
if (TextBox4_pa.Text == "1")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1,200,140,76,80);

}
if (TextBox4_pa.Text == "2")
{
p1.StartCap = LineCap.ArrowAnchor;
Gfx.DrawLine(p1, 210, 140, 190, 50);

}
if (TextBox4_pa.Text == "3")
{
p1.StartCap = LineCap.ArrowAnchor;
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.?

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)
 
im going to do what u said. kindly make me clear he 5th point.
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)
 
smoky_flame via DotNetMonster.com said:
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.
 
ive used string.split and it delimited th commas.
but how can i used GDI+ with it?
 
smoky_flame via DotNetMonster.com said:
ive used string.split and it delimited th commas.

And have you parsed the strings into integers?
but how can i used GDI+ with it?

Well, you really haven't given nearly enough details as to what you
want to actually *do* with the numbers when you've parsed them. You've
given an example, but it doesn't explain where the points defining the
lines have come from. You'll need to work that out yourself.
 
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(TextBox4_pa.Text, out ipair))
{
Point[] pointPair = pointPairs[ipair];

p1.StartCap = LineCap.ArrowAnchor;
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top