Here is the code:
public void calculations()
{
int value;
try
{
if ((string.IsNullOrEmpty(txtrate.Text)) || (string.IsNullOrEmpty(txttotalkm.Text)))
{
MessageBox.Show("Fill both the Values", "Try Again", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if ((int.TryParse(txtrate.Text, out value)) && (int.TryParse(txttotalkm.Text, out value)))
{
int rate = int.Parse(txtrate.Text.Trim());
int km = int.Parse(txttotalkm.Text.Trim());
decimal gross = rate * km;
decimal NBT = (gross * 8 / 100);
decimal vat = ((gross + NBT) * 11 / 100);
decimal total = vat + NBT + gross;
string snbt = String.Format("{0:Rs 0.00}", NBT);
string svat = String.Format("{0:Rs 0.00}", vat);
string stotal = String.Format("{0:Rs 0.00}", total);
lblnbt.Visible = true;
lblnbt.Text = snbt;
lblvat.Visible = true;
lblvat.Text = svat;
lbltotal.Visible = true;
lbltotal.Text = stotal;
string ltnbt = lblnbt.Text.ToString();
string ltvat = lblvat.Text.ToString();
string lttotal = lbltotal.Text.ToString();
int inbt = Convert.ToInt32(lblnbt.Text);
int ivat = Convert.ToInt32(lblvat.Text);
int itotal = Convert.ToInt32(lbltotal.Text);
//CreateWordDocument(@"C:\temp\test.docx",
// @"C:\temp\new.docx");
clear();
}
else
{
MessageBox.Show("Wrong Values Please Check again", "Try Again", MessageBoxButtons.OK, MessageBoxIcon.Information);
clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
When running the program, it says:
input string was not in a correct format error
I must say I'm just trying to code and learn, not a pro, I just can't find out the issue.
Tried removing the try...catch box and see the exception it says this:
If there is an easier way to do this, just let me know.

int.Parsecausing the issue here useint.TryParseinstead. Hope that you are theNthperson come up with this question