hello guys im having a little problem here.
I have few text boxes and few labels. User enters values into textboxex. Values in lables are from XML file, so the program reads for egz <price>30</price> and this price is set as a label label1 => 30 And now im wondering how to multiply a value entered by user by the value of a label ( in this case 30, but can be any number)

thank you :)

        int answer1 = 0;            
        answer1 = (textboxnumber1/100)*label1 + textboxnumber2 + textboxnumber3 + textboxnumber4;
        total1.Text = answer1.ToString();

        "Error  1   Operator '*' cannot be applied to operands of type 'int' and 'System.Windows.Forms.Label'   c:\users\boss\documents\visual studio 2010\Projects\tabs\tabs\Form1.cs  103 23  tabs


You have to parse the 'string' data to the appropriate simple type before the calculation.

for instance,

double no1=double.Parse(textboxnumber1.Text);
double no2=double.Parse(Label1.Text);

You may also use XXXXX.TryParse method.


double no1;
double.TryParse(textboxnumber1.Text,out no1);

You can try like this also.....converting lable value to int

            int answer1 = 0;
            answer1 = (Convert.ToInt32(textboxnumber1.text) / 100) * Convert.ToInt32 (label1.text) + Convert.ToInt32(textboxnumber2.text) + Convert.ToInt32(textboxnumber3.text) + Convert.ToInt32(textboxnumber4.text);
            total1.Text = answer1.ToString();

Hope this will help.

Restrict your test box to only except ints so that the user can't enter charactors into the textbox.

convert the int value to string thn it will work effectively

convert the int value to string thn it will work effectively

This would mean that charactors can be entered into the textbox which would cause errors. Best thing to do would be restrict/ validate what the user can enter.