FormatException: Input string was not in a correct format.

M

Maria

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
 
K

Ken Cox [Microsoft MVP]

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]
 
M

Maria

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
 
M

Maria

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 said:
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/Technology/Tutorials/BestPractices.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top