Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using * in textbox problem

Status
Not open for further replies.

baran121

Programmer
Sep 8, 2005
337
TR

hi,
i coudnt solve this problem. can you tell me please what is the problem i have in code below :


txtprice.Text = (txtprice.Text) - (txtprice.Text)*(rdr["isk"])/100;

 
sorry the code below:

txtprice.Text = (txtprice.Text) - (txtprice.Text)*(rdr["isk"].ToString)/100;
 
I'd assume you're having problems because you're trying to do calculations with string values. I don't know what kind of numbers you've got in your textbox (so I'm assuming integers for this example). You could try something like (for example purposes):
Code:
int textval = Convert.ToInt32(textBox1.Text);
int newval = textval - textval * Convert.ToInt32("12") / 100;

textBox1.Text = newval.ToString();
There will be other ways but this should hopefully point you in the right direction.

Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
to follow up on what Andy wrote. C# does not implicitly convert types like VB.
this will throw an exception in C#.
Code:
string s =  1;
this will not throw an exception
Code:
string s =  1.ToString();
in your case you are trying to use strings as numbers. and then set the numeric value to a text box. you need to convert the values first, as Andy has demonstrated.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top