[thelist] Re: if...or...then in asp
Paul Cowan
paul at wishlist.com.au
Mon Feb 25 15:37:01 CST 2002
Scott Dexter [mailto:sgd at ti3.com] wrote:
> That is correct. VBScript has *never* done short-circuit evals. It
> evaluates the entire expression, always....
Indeed. And for what it's worth, here's a handy-dandy function we use to do
what the original poster wanted; I thought I'd share it with you all as a:
<tip type="ASP Utility Function" author="Paul Cowan">
The following function is useful in particular for dealing with request.form
objects. It will save you a HEAP of time in getting values out of the
request without having to do a bunch of checks each time.
function ConvertToLong(varInput, lngDefault)
dim lngOutput
lngOutput = lngDefault
if ("" & varInput <> "") then
if (isNumeric(varInput)) then
lngOutput = clng(varInput)
end if
end if
ConvertToLong = lngOutput
end function
Usage:
lngUserID = ConvertToLong(request.querystring("userid"), null)
or
if (ConvertToLong(request.form("quantity"), 0) > 0) then ...
where the 0 or null is whatever value you want the variable to
take if the request variable is empty or otherwise invalid.
Of course, it's easy enough to write ConvertToDouble, ConvertToBoolean,
etc...
</tip>
More information about the thelist
mailing list