473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

FormatException: Input string was not in a correct format.

Hello !

I'm a newbie trying to learn something about asp.net. To start with
something easy I made a page that convert from Celsius to Fahrenheit.

The code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim x As Double = ((Double.Parse(Me.txtCelsius.Text, NumberStyles.Any) *
1.8) + 32)

Me.txtFarenheit.Text = CType(x, String)

End Sub
But when I try to open the page on the remote server I get this error :

FormatException: Input string was not in a correct format.
I have search the net - but only found info about database and sql.

Can someone guide me in the right direction ??

Maria




Nov 18 '05 #1
4 2760
Hi Maria,

You'll get that error if the txtCelsius is empty. Perhaps you should trap
for an empty string like this?

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If txtCelsius.Text = "" Then
txtFarenheit.Text = "Please provide a value."
Exit Sub
End If
Dim x As Double = _
((Double.Parse(Me.txtCelsius.Text, _
Globalization.NumberStyles.Any) _
* 1.8) + 32)
Me.txtFarenheit.Text = CType(x, String)
End Sub

Ken
Microsoft MVP [ASP.NET]
"Maria" <ma*****@nospamstart.no> wrote in message
news:ec**************@TK2MSFTNGP12.phx.gbl...
Hello !

I'm a newbie trying to learn something about asp.net. To start with
something easy I made a page that convert from Celsius to Fahrenheit.

The code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim x As Double = ((Double.Parse(Me.txtCelsius.Text, NumberStyles.Any) *
1.8) + 32)

Me.txtFarenheit.Text = CType(x, String)

End Sub
But when I try to open the page on the remote server I get this error :

FormatException: Input string was not in a correct format.
I have search the net - but only found info about database and sql.

Can someone guide me in the right direction ??

Maria






Nov 18 '05 #2
Hello Ken !

I got this error even if txtCelsius is not empty. But in the
error.descripton there was a reference to my local cache - so I tried to
build the site again, but in a different folder on the remote server.
Exactly the same code - and this time it's ok ? Probably some mistake by me
when I created the site..

Thanks !!

Maria
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Maria,

You'll get that error if the txtCelsius is empty. Perhaps you should trap
for an empty string like this?

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If txtCelsius.Text = "" Then
txtFarenheit.Text = "Please provide a value."
Exit Sub
End If
Dim x As Double = _
((Double.Parse(Me.txtCelsius.Text, _
Globalization.NumberStyles.Any) _
* 1.8) + 32)
Me.txtFarenheit.Text = CType(x, String)
End Sub

Ken
Microsoft MVP [ASP.NET]

Nov 18 '05 #3
Probably you are typing an invalid number in the txtCelsius.Text like characters etc. I don't see any other reason. Try to debug line by line and see which line fails

Just as a side note, you can use x.ToString() to convert into string. Here is a good best practises guide : http://www.dotnetspider.com/Technolo...tPractices.asp

Nov 18 '05 #4
Hello Tojo

Well - I get the same error if I type in a valid numer. But when I
installed it to another folder - it was ok..
Maria
"TOJO" <an*******@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
Probably you are typing an invalid number in the txtCelsius.Text like characters etc. I don't see any other reason. Try to debug line by line and
see which line fails.
Just as a side note, you can use x.ToString() to convert into string. Here is a good best practises guide :
http://www.dotnetspider.com/Technolo...Practices.aspx

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: .YC | last post by:
Hi, I was trying on the following code n I got an exception. Can anyone tell me whats wrong? using System; namespace Module_2 { /// <summary>
0
by: zee | last post by:
System.FormatException: Input string was not in a correct format. I am inputting into a databse the value that causes an error is a double, If I leave that field blank then I catch the exception it...
2
by: sbox | last post by:
I've got an error "System.FormatException: Input string was not in a correct format." while I'm implementing a datagrid and a textbox What's wrong with it? Sub Button1_Click(sender As Object, e...
4
by: Maria | last post by:
Hello ! I'm a newbie trying to learn something about asp.net. To start with something easy I made a page that convert from Celsius to Fahrenheit. The code : Private Sub Button1_Click(ByVal...
1
by: Robin HOIZEY \(Hotmail\) | last post by:
Hi, I'm using the OdbcDataReader.GetValues method (.NET Framework 1.1) to populate an object array with the result of a SQL command. The Database engine is Oracle 9.0.2. When getting...
2
by: vooose | last post by:
Consider executing a stored procedure which has a single INT arg: SqlCommand command = new SqlCommand("Some_Stored_Procedure", conn); command.CommandType =...
0
by: bnlockwood | last post by:
G'day all, Thank you in advance for anyone that can help. I have a shopping cart datagrid on my c# asp.net page. This is the code: ------------------------------------- <asp:datagrid...
0
by: Avi | last post by:
A CreateUserWizard contorl receives new user details, adds the user to the database, tries to send a confirmation mail message and stops with a "System.FormatException: The specified string is not...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.