Hi
can someone help me with this error in microsoft visual studio for the following code.
An unhandled exception of type 'System.FormatE xception' occurred in mscorlib.dll
I think it occurs at
decimal conversion1 = Convert.ToDecim al(txtConversio n1.Text);
thanks
can someone help me with this error in microsoft visual studio for the following code.
An unhandled exception of type 'System.FormatE xception' occurred in mscorlib.dll
I think it occurs at
decimal conversion1 = Convert.ToDecim al(txtConversio n1.Text);
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Conversions
{
public partial class Conversions : Form
{
string[,] lengths = {
{"Select conversion"," "," "," "}, // 2D array to Load comboBox with lenghts
{"Miles to Kilometers","Miles","Kilometers","1.6093"},
{"Kilometers to Miles","Kilometers","Miles","0.6214"},
{"Feet to Metres","Feet","Metres","0.3048"},
{"Metres to Feet", "Metres", "Feet", "3.2808"},
{"Inches to Centimetres", "Inches", "Centimetres","2.54"},
{"Centimetres to Inches", "Centimetres", "Inches", "0.3937"}
};
public Conversions()
{
InitializeComponent();
for (int i = 0; i < lengths.GetLength(0); i++)
{
comboBox1.Items.Add(lengths[i, 0]);
}
comboBox1.SelectedIndex = 0;
}
private void btnCalculate_Click(object sender, EventArgs e)
{
int selectedIndex = comboBox1.SelectedIndex; // select element in comboBox
decimal convrate = Convert.ToDecimal(lengths[selectedIndex, 3]);
decimal conversion1 = Convert.ToDecimal(txtConversion1.Text);
decimal result = conversion1 * convrate;
txtConversion2.Text = result.ToString("n");
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = comboBox1.SelectedIndex;
lblConversion1.Text = lengths[selectedIndex, 1];
lblConversion2.Text = lengths[selectedIndex, 2];
txtConversion1.Text = "";
txtConversion2.Text = "";
}
}
}
thanks
Comment