In asp classic: How can I make sure that a variable can be cast as an int?

Posted by Tchalvak on Stack Overflow See other posts from Stack Overflow or by Tchalvak
Published on 2010-04-30T00:27:08Z Indexed on 2010/04/30 0:37 UTC
Read the original article Hit count: 181

Filed under:
|

The following function was suggested to me:

' Defines a forced casting function, which "casts" anything that it can't detect as a number to zero.
    Function MakeInteger(val)
      If IsNumeric(val) Then
        MakeInteger = CInt(val)
      Else
        MakeInteger = 0
      End If
    End Function

Unfortunately there appear to be some things that return true for IsNumeric() but still can't be cast as an int. Is there any better check to use?

© Stack Overflow or respective owner

Related posts about asp-classic

Related posts about casting