0

I have this line of code that should convert a label and a textbox to int32 and then subtract them with eachother...

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);

retur is a int aswell.

This line gives me the error: Input string was not in a correct format. (I've never recived this error before)

WHY?! Am I missing something?

Hugo Löwgren
  • 47
  • 1
  • 1
  • 8
  • Looks like you forget to use `.Text` properties of your labels. But what are their values and what is your `CurrentCulture` exactly? – Soner Gönül May 23 '14 at 06:43
  • their input is whatever the user inputs in the UI – Hugo Löwgren May 23 '14 at 06:48
  • @Raging I don't think so, this isn't how Stack Overflow works. You can't just edit your question and make *fundamental changes* to the question you're asking. The edits invalidate all of the existing answers as well. That tells you it's a bad edit. – Cody Gray - on strike May 23 '14 at 13:00
  • So roll the edit back, @Raging. I don't think it's worth the effort, so I didn't do it myself. It looks like at least 2 other people agree with you though. I don't have a vested interest here, my answer isn't one of the ones that would be invalidated. But I'm not going to take action that I disagree with. If the asker has a new question, he should post a new question. – Cody Gray - on strike May 24 '14 at 02:41

2 Answers2

4

You need to use the Text property to get the content of the Textbox and Label.

Try This:

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
2

You are not passing string to Convert.ToInt32(string value) rather passing the control itself i.e TextBox and Label. You have to use Text property to get the text in the Textbox and Label.

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);
Adil
  • 146,340
  • 25
  • 209
  • 204