I'm doing some error debugging trying to get the er开发者_高级运维rors on our website down to a minimum and there seems to be an error that is popping up quite a lot
Conversion from string "" to type 'Double' is not valid.
I'm unable to replicate this problem but I can see that it is happening.
I've been looking through the code in one of the pages and strolled across this
Dim varWeek As String
If varWeek < 10 Then
'Do something'
End If
Could this be causing the problem as it is trying to see if a String
is less than 10
which is an Integer
?
As I said before as I am unable to see this error in the first place so changing this to an Integer
doesn't change anything on my system.
Thanks.
I cannot see any reason as to why this conversion should result in a double. Most likely you have some operation where a double should fit.
In general, I would use conversions before attempting operations, e.g.:
If Convert.ToInt32( varWeek ) < 10 Then
and so on.
I think you answered yourself.
Try converting that String variable to integer. For example use:
Dim varWeek As String
If Val(varWeek) < 10 Then
'Do something
End If
I'm not sure if you already tried, but did you use the Try Catch statement? That way you could see where is the error coming from.
Debug on buddy ;)
The error is being caused because your string is empty "".
You should do some kind of error checking on the string before comparing it to a number.
You could do something like this:
Dim varWeek As String
If IsNumeric(varWeek)
If varWeek < 10 Then
Do something
End If
Else
Handle your error here, probably feed back to the user that their input is invalid
End If
If your message is the exception's message, it's a convertion failure. If you pass a empty string (your "") to Convert.ToDouble, Double.Parse (in C#), it launch an FormatException.
You can avoid this using Double.TryParse.
精彩评论