473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Mar 15 '08 #1
8 3868
On Sat, 15 Mar 2008 11:42:57 -0700, smoky_flame via DotNetMonster.com
<u42139@uwewrote:
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
Mar 15 '08 #2
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.?

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.com
http://www.dotnetmonster.com/Uwe/For...sharp/200803/1

Mar 15 '08 #3
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.?

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

Mar 15 '08 #4
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.?

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.com
http://www.dotnetmonster.com/Uwe/For...sharp/200803/1

Mar 15 '08 #5
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.com
http://www.dotnetmonster.com/Uwe/For...sharp/200803/1

Mar 16 '08 #6
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.com
http://www.dotnetmonster.com/Uwe/For...sharp/200803/1

Mar 16 '08 #7
On Sun, 16 Mar 2008 00:20:41 -0700, smoky_flame via DotNetMonster.com
<u42139@uwewrote:
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
Mar 16 '08 #8
On Mar 15, 7:14 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Sat, 15 Mar 2008 11:42:57 -0700, smoky_flame via DotNetMonster.com

<u42139@uwewrote:
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.

Mar 18 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
12
by: Clifford Stern | last post by:
In a function that returns two values, how do you read them? Consider the following function: int addsub(int x,int y) {int a,b; a=x+y; b=x-y; return(a,b);} trying to read the results, for...
1
by: samir dsf | last post by:
hi i can send and retrieve a single value. but now i have around 3-4 values which i want to pass, from a link and receive in another page. here is how i am currently doing: Dim urlParams As...
5
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
9
by: Karl O. Pinc | last post by:
I want to return multiple values, but not a set, only a single row, from a plpgsql function and I can't seem to get it to work. (I suppose I'd be happy to return a set, but I can't seem to make...
1
by: Rama Jayapal | last post by:
hi i am developing a web application where i have to read multiple XML feeds amd store their values to database but i require the same type of fields from multiple XML feeds like for...
0
by: waterfall | last post by:
Hi, Im developing a C# web application in VS2005. Ive 2 textboxes for user input and a button. First textbox gets string as input(e.g, ItemA, ItemB etc.) Second textbox get int as input(1,2,3,4...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
0
by: Maric Michaud | last post by:
Le Thursday 28 August 2008 03:43:16 norseman, vous avez écrit : Disctionaries are hash tables with a unique key and constant time lookup. What you want could be implemented as a complex data...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.