Basically refreshing some C# knowledge making a converter; I'm trying to make a window pop up when no numbers are in the textbox
but when I click the button
I get this error:
System.FormatException: 'Input string was not in a correct format.'
private void btnConvert_Click(object sender, EventArgs e)
{
// Killogram convertion
double i = double.Parse(txtboxAmount.Text);
if (comboBoxFrom.SelectedItem == "KG" && comboBoxTo.SelectedItem == "LB")
{
double conver = i * 2.20462262185;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "LB" && comboBoxTo.SelectedItem == "KG")
{
double conver = i / 2.2046;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "ST" && comboBoxTo.SelectedItem == "KG")
{
double conver = i * 6.35;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
// Pound convertion
if (comboBoxFrom.SelectedItem == "LB" && comboBoxTo.SelectedItem == "ST")
{
double conver = i / 14;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "ST" && comboBoxTo.SelectedItem == "LB")
{
double conver = i / 14;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "LB" && comboBoxTo.SelectedItem == "KG")
{
double conver = i / 2.205;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
// Stone convertion
if (comboBoxFrom.SelectedItem == "ST" && comboBoxTo.SelectedItem == "LB")
{
double conver = i * 14;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "LB" && comboBoxTo.SelectedItem == "ST")
{
double conver = i / 14;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
if (comboBoxFrom.SelectedItem == "LB" && comboBoxTo.SelectedItem == "KG")
{
double conver = i / 2.205;
double converdec = Math.Round((Double)conver, 2);
txtBoxResult.Text = "Converted Amount : " + converdec;
}
else if (comboBoxFrom.SelectedItem == null && comboBoxTo.SelectedItem == null)
{
MessageBox.Show("Enter a valid weight amount and/or select a unit of measurement.");
}
}
The line causing the issues is below I string turning it into a string with to string but no luck
double i = double.Parse(txtboxAmount.Text);