473,320 Members | 1,900 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,320 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 2758
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.