Input string was not in a correct format?

J. Scott Elblein

Well-known member
Joined
Dec 14, 2006
Messages
166
Location
Chicago
Programming Experience
10+
I have this line of code:

VB.NET:
If Not intPagesCount = Convert.ToInt32(strTotalPages) Then 'do stuff

intPagesCount is holding an integer, like 1, and strTotalPages holds a string like "34".

When I run it through a try catch, the error message on that line says this:

Input string was not in a correct format.

Can anyone tell me what I'm doing wrong? The strange thing is on a different routine I use the exact same code and it works great?

Thanks :)
 
Hi there,

I just did a quick test:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intpagescount As Integer = 1
Dim strTotalPages As String = "34"


If Not intpagescount = Convert.ToInt32(strTotalPages) Then
MsgBox("No Match")
Else
MsgBox("Match")
End If
End Sub
Which works fine. what are you inputs for the variables?
 
Hi blounty.

Thanks for replying. I made a blunder and during parsing of the string, accidentally left an apostrophe before the number (it looked like this "'34"). So in the debugger tooltip, it's really hard to see it next to the quotes with the smaller font. I guess I just was a bit rushed and wasn't looking at the screen 2 inches form my face in order to see it, lol!

Sometimes I wish we were allowed to delete our own posts on here when things like that happen. :)
 
Back
Top