Hi
can someone help me with this error in microsoft visual studio for the following code.
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
I think it occurs at
decimal conversion1 = Convert.ToDecimal(txtConversion1.Text); -
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
1 1886
This exception means that: "value is not a number in a valid format."
You have to check what exactly is in your txtConversion1.Text at the moment of convertsion. Set a breakpoint there and find out. The string you're trying to convert may be invalid, or empty.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tommy DN |
last post by:
I'm working with Oracle Form Builder and I needed a trigger to check
something when I delete a record. I made a trigger on ' KEY-DELREC ' and
I've written this code ( it's just a test, the delete...
|
by: Professor Frink |
last post by:
First off, I apologize if this gets long. I'm simply trying to give you all
enough information to help me out. I'm writing (almost finished, actually),
my first VB.Net application. It's a forms...
|
by: Tony Hamill |
last post by:
Hi,
I am trying to set up a VERY simple project to send message to MSMQ from
..Net using C#. When I run my code it throws an exception
"An unhandled exception of type...
|
by: Anders Borum |
last post by:
Hello!
I am working on improving my threading skills and came across a question.
When working with the ReaderWriterLock class, I am getting an unhandled
exception if I acquire a WriterLock with...
|
by: Craig831 |
last post by:
First off, I apologize if this gets long. I'm simply trying to give you all
enough information to help me out. I'm writing (almost finished, actually),
my first VB.Net application. It's a forms...
|
by: Chuck Hartman |
last post by:
I have a Windows service that requests web pages from a site using an
HttpWebRequest object. When I try to request a page from an ASP.NET 2 site,
I get a WebException with message "The remote...
|
by: Lucvdv |
last post by:
Can someone explain why this code pops up a messagebox saying the
ThreadAbortException wasn't handled?
The first exception is reported only in the debug pane, as expected.
The second (caused by...
|
by: Simon Tamman {Uchiha Jax} |
last post by:
Now this is bugging me.
I just released software for a client and they have reported an unhandled
stack overflow exception.
My first concern is that the entirity of the UI and any threaded...
|
by: royjm18 |
last post by:
Dim MyMoney As Single
Dim DRolls As Integer
Dim NRolls As Integer
Dim PRolls As Integer
Dim QRolls As Integer
Dim RemainingChange As Single
MyMoney = 28.24
QRolls = Int(MyMoney / 10)...
|
by: sweety56 |
last post by:
The error I get is
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
This points to
using System;
using...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |