CLng and IsNumeric

Results 1 to 3 of 3

Thread: CLng and IsNumeric

  1. #1
    Join Date
    Dec 1969

    Default CLng and IsNumeric

    I use CLng to make sure my JobID is a number...<BR><BR>iJobID = CLng(iJobID)<BR><BR>But of course, when JobID is not numeric this throws a type error...<BR><BR>Do I need to do something like<BR><BR>If IsNumeric(iJobID) Then<BR>iJobID = CLng(iJobID)<BR><BR>But then is there any point? Couldn&#039;t I just do<BR><BR>If IsNumeric(iJobID) Then ....?<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: CLng and IsNumeric

    So you need to decide what you are going to do if the ijobID is not numeric!<BR><BR>If IsNumeric(iJobID) Then<BR> iJobID = CLng(iJobID)<BR>Else<BR> &#039;oops iJobID is not numeric<BR>end if

  3. #3
    Join Date
    Dec 1969

    Default And CLNG can fail even if isNumeric!

    &#060;%<BR>iJobID = 987654321881119<BR>If isNumeric(iJobID) Then<BR> Response.Write "Yep, it&#039;s numeric!"<BR> iJobID = CLng( iJobID ) &#039; CRASH! ERROR! <BR>End If<BR>%&#062;<BR><BR>The only type conversion that is *guaranteed* to work if a string isNumeric is CDBL. And of course many CDBL values are too large (or small) to be converted to a long integer.<BR><BR>So, if you want a *good* test:<BR><BR>&#060;%<BR>xJobID = 987654321881119<BR>iJobID = "NO GOOD"<BR>If isNumeric(xJobID) Then<BR> xJobID = CDBL( xJobID )<BR> If xJobID &#060;= 2000000000 AND xJobID &#062;= -2000000000 Then<BR> iJobID = CLng( xJobID )<BR> End If<BR>End If<BR>Response.Write "iJobID is " & iJobID<BR>%&#062;<BR><BR>Now you get to decide if that&#039;s worth the trouble.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts