Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If otherwise error " The <= operator can not be applied to operands of type "TextBox" and "int")

I have just started programming and have an error that I can not fix.

If otherwise error " The <= operator can not be applied to operands of
type "TextBox" and "int").

private void bn_CocaCola_Click(object sender, EventArgs e)
    {
        int GetränkeWert = 2;

    if (tbh_GeldAs <= GetränkeWert)
    {
        tbh_GeldAs.Text = ("Endnehmen sie Ihr Getränk");
    }
    else
    {
        tbh_GeldAs >= GetränkeWert;
        tbh_GeldAs.Text = ("Sie müssen Geld einzahlen");
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Error messages are there to help us so try to look at what it is telling you. I looked at the error message in your post and it states that your expression…

tbh_GeldAs <= GetränkeWert

is a comparison of these types.

TextBox <= int.

So what is a textbox? It holds some text but you have to look at the Textbox.Text property.

tbh_GeldAs.Text <= GetränkeWert

But now this is comparing a string like "123" to an int and it still doesn’t work! You need to change that string to a number.

Try:

Convert.ToInt32(tbh_GeldAs.Text) <= GetränkeWert

And while I hope this solves your problem, my real answer is to take the time to look at the error message and see what it’s saying because they are usually quite helpful.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading