0

i have problem my teacher failed to solve, there are no errors but when i debug the program i get exception saying:"when converting string todate time, parse the string to take the date before putting each variable into the DateTime object". In this line:"

//stopa poreza
double brutoPlaca = Convert.ToDouble(textBox3.Text);"

original code:

string stopaDoprinosa; double Doprinos = 0;
string stopaPoreza; double Porez = 0;
double netoPlaca;
//doprinos
if (textBox2.Text == "Osijek")
{ stopaDoprinosa = "13%"; }
else
{ stopaDoprinosa = "8%"; }
//stopa poreza
double brutoPlaca = Convert.ToDouble(textBox3.Text);
if (brutoPlaca <= 3000)
{ stopaPoreza = "10%"; }
else
{ stopaPoreza = "20%"; }

//porez
if (stopaPoreza == "10%")
{ Porez = 0.1; }
if (stopaPoreza == "20%")
{ Porez = 0.2; }

//neto plaća
netoPlaca = brutoPlaca * Porez;
if (stopaDoprinosa == "8%")
{ Doprinos = 0.08; }
if (stopaDoprinosa == "13%")
{ Doprinos = 0.13; }

Djelatnik d = new Djelatnik(textBox1.Text, textBox2.Text, brutoPlaca,stopaDoprinosa,Doprinos,stopaPoreza,Porez,netoPlaca);
Djelatnici.Add(d);
assylias
  • 321,522
  • 82
  • 660
  • 783
Martin Markovic
  • 99
  • 2
  • 2
  • 8

2 Answers2

1

To convert a string into a double number use double.Parse() or double.TryParse() method, like that:

double brutoPlaca = double.Parse(textBox3.Text);
Adrian Ciura
  • 1,102
  • 1
  • 9
  • 14
  • @MartinMarkovic: What symbol are you using to describe the fraction part of the number (comma or dot)? I.e. in the text box do you enter "123.45" or "123,45"? English decimal numbers use dot for that, so the double.Parse() expects the number to be in the following format: "123.45". – Adrian Ciura Nov 17 '12 at 15:14
0

Turn on stop on thrown exception in debugger. That is in visual studio, go to Debug->Exceptions then tick the box thrown next to clr exceptions.

Visual Studio: How to break on handled exceptions?

As you have not given us the line, and have had to remove a catch, I assume you have not done this.

Community
  • 1
  • 1
weston
  • 54,145
  • 21
  • 145
  • 203
  • If i understood what you told me i alredy gave you the line where exception pops:"//stopa poreza double brutoPlaca = Convert.ToDouble(textBox3.Text);" – Martin Markovic Nov 17 '12 at 13:19