Convert to numeric

I wrote following function in VBScripts to over come the fundamental problem that I faced when trying to convert any valid numeric value through an ADODB Recordset. Basically the VBScripts IsNumeric() is not working appropriately, it does not parse any valid numeric value. Maybe this is because of some internal issue with the VBScript engine, any way I wrote the following function to convert the given value to its corresponding numeric format. The NULLs, Alpha or Alpha numeric and Empty values will get converted to zero. The function will return either zero or the passed value, only if it can convert to any other numeric type without generating a runtime errors

Function ConvertTonumber(strVal)

on error resume next
  dim numberVal

  numberVal = 0

  if not isnull(strVal) then
     numberVal = cdbl(strVal)
  end if

if Err.Number<>0 then
end if
ConvertTonumber = numberVal
End Function


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s