Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I've made a program but I'm having trouble trying to execute a condition if the value entered in the textbox by the user is greater than the value in a label then the value doesn't get plotted on the graph


Currently my graph plots values like this:

chart1.Series["Data"].Points.AddXY(14, txtTest2.Text);


but I want a condition to say if the txtTest2.Text value is greater than the lblvalue then it doesn't show in the chart.


What I have tried:

if (txtTest2.Text) > lblvalue
{

}

but I can't use the > 
Posted
Updated 1-Mar-21 19:56pm

txtText2.text is a string.
A string could not be compared with a numeric Variable.
So ... you should convert your Textbox-Content to the same type than lblvalue should contain ...
 
Share this answer
 
v2
Comments
Member 15086979 1-Mar-21 10:50am    
I'm not sure I understand what you mean.

The label contains a number, and this is constructed via a calculation, e.g.
double calculation = result * 0.20;
lblvalue.Text = calculation.ToString();


I tried using int.Parse(txtText2.Text) too
Dave Kreskowiak 1-Mar-21 11:29am    
No, the label will NEVER contain a number. It will always contain a string, even if it looks like a number.

You should not be comparing the parsed value from the TextBox to the string in the label. What you should be doing is parsing the value in the TextBox to a value type, like a double in your case and comparing that to the value of calculation.

DO NOT STORE DATA YOU ARE WORKING ON IN CONTROLS! Store them in data structures or some kind to make it far easier to work on. Controls are there to display data, and edit it, not store it.
Ralf Meier 1-Mar-21 11:32am    
OK ... you were some seconds faster ... ;-)
Ralf Meier 1-Mar-21 11:32am    
Perhaps you shouuld write something more about what you are doing there ...
Label.Text contains allways a STRING - the same is a Textbox - Textbox.Text is also ALLWAYS a string.
But perhaps your string has a numeric format ... so if you want to compare them you have to convert them to the right type.
What you have done is to be seen in your code-snippet - you made a string from a calculation ...

If you want to compare numerics you should use numerics.
Compare Doublke with Double - for example.

Also ... it doesn't makes any sense to assign strings to your Chart as X-Y-values. Also at this places it is necessary to assign numerics ...
Dave Kreskowiak 1-Mar-21 11:52am    
;)
Quote:
I want a condition to say if the txtTest2.Text value is greater than the lblvalue then it doesn't show in the chart


Stop!
Think of it. Label, textbox, etc. is just a control. You have to work on data (graph data). So, all what you need is to compare value entered by the user with graph data...
Got it?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900