Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Error CS1503 Argument 1: cannot convert from 'System.Windows.Forms.TextBox' to 'string'

What I have tried:

private void fullTotalButton_Click(object sender, EventArgs e)
{
const decimal TAXRATE = 0.12m;
decimal val1 = decimal.Parse(MealCost.Text);
decimal result = val1 * TAXRATE;
taxAmount.Text = result.ToString("C");
decimal outcome = val1 + result;
fullTaxLabel.Text = outcome.ToString("C");
decimal val7 = decimal.Parse(tipCalculate);
decimal ending = val7 + outcome;
tipamountBox.Text = ending.ToString("C");
Posted
Updated 27-Jan-17 20:07pm
Comments
j snooze 27-Jan-17 17:28pm    
Gotta get that homework done before the teacher finds out. I can't really tell from your code but somewhere you are referencing a textbox without using the .Text property to either set the value of it, or get the value from it.
Afzaal Ahmad Zeeshan 27-Jan-17 17:59pm    
One of the objects in this code is of type TextBox and you are trying to use it somewhere, string type is expected.

Since you haven't shared anything other than this code, we are not able to help you with this as we don't know anything at all; what your typing for objects is, what comes from where.
[no name] 27-Jan-17 18:20pm    
The error message is plain. And where the error is, is pretty clear too. But that is all I care to do for such a rude posting.
CHill60 27-Jan-17 19:32pm    
Hints:
1. On which line was this exception reported?
2. Post ALL the relevant code ... for example what is fullTaxLabel? Do I trust your naming conventions? No.
3. To get a timely response to your problems
a) Avoid anything that suggests this may be "urgent" to you (it is not)
b) respond immediately to questions in comments (you haven't)
c) Include all the relevant information

1 solution

Look at this line:
decimal val7 = decimal.Parse(tipCalculate);

That needs to be a string parameter - so reference the Text property:

decimal val7 = decimal.Parse(tipCalculate.Text);

In future, if you look at the error message in Visual Studio, you can double click it, and you will be taken to the line with the error directly.
 
Share this answer
 
Comments
Jon McKee 28-Jan-17 4:12am    
Not to mention the jump from val1 to val7. Whatever happened to descriptive variables? Well done though, this seems plausible as the issue despite the lack of any description of the types involved.
OriginalGriff 28-Jan-17 4:23am    
What gets me is that it would have been just as easy to type "cost" instead of "val1", "tip" instead of "val7" and so on. I can only assume that he tried "val2" to "val6" inclusive - somehow - and got no result he liked. :sigh:

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