Hier ist der Code:Eingabezeichenfolge war nicht in einem korrekten Format Fehler
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);
}
}
Wenn das Programm läuft, heißt es:
Eingabezeichenfolge war nicht in einem korrekten Format Fehler
Ich muss sagen, ich versuche nur zu programmieren und zu lernen, kein Profi, ich kann das Problem einfach nicht herausfinden.
Versucht das try...catch
Box zu entfernen und die Ausnahme sehen es heißt dies:
Wenn es einen einfacheren Weg, dies zu tun, lass es mich wissen.
Auf welcher Linie erhalten Sie die Ausnahme? –
Der "int.Parse", der das Problem verursacht, verwendet stattdessen "int.TryParse". Hoffen Sie, dass Sie die 'Nth' Person sind, die diese Frage –
@diiN_ @ int ivat = Convert.ToInt32 (lblvat.Text); – Binku