NewCInt Function:
A more convenient CInt.
Description:
The VbScript CInt function raises an exception when a null value, blank string, or non-numerical string is passed. NewCInt Function overcome this returning 0 if the input is null, blank, or not a number.
Syntax:
intOutput = NewCInt(strInput)
Example:
<%
Response.Write NewCInt("") '--- returns: 0
Response.Write NewCInt("AAA") '--- returns: 0
Response.Write NewCInt(123,45) '--- returns: 123
%>
ASP Source Code:
<%
Function NewCInt(strInput) --- 'Remove any trailing or leading spaces strInput = trim(strInput) '--- If the input is null, blank, or not a number then set it to zero if strInput = "" or isNull(strInput) or not isNumeric(strInput) then strInput = "0" '--- Convert it to an integer using the regular cInt function and return it. NewCInt = CInt(strInput) End Function
%>
|