views:

44

answers:

1

In asp classic, the cint() function or procedure or whatever it is won't allow me to cast arbitrary strings, like "bob" or "null" or anything like that. Is there anything that will allow me to simply cast integers, numeric strings, and arbitrary strings to actual integers, with some sane default like 0 for strings?

+4  A: 

How about making a function like below, then call this:

Function MakeInteger(val)
  If IsNumeric(val) Then
    MakeInteger = CInt(val)
  Else
    MakeInteger = 0
  End If
End Function
BradBrening
That works (started having to debug an asp app yesterday, jus' trying to get past it).
Tchalvak
Hmmm, turns out that this doesn't actually work, because you can still get casting problems, e.g. Microsoft VBScript runtime error '800a0006'Overflow: 'CInt'
Tchalvak
Use Clng() instead, it has a bigger range.
My Other Me
Upvote for myotherme. Since the question pertained to inability to use CInt and the use of the word "integers" throughout, I stuck with the CInt function in my example. In VBScript, an Integer can hold a number from -32,768 to 32,767. A Long on the other hand can hold a number from -2,147,483,648 and 2,147,483,647.
BradBrening