asp classic - VBScript conditional short-circuiting workaround -
i have large classic asp app have maintain, , repeatedly find myself thwarted lack of short-circuit evaluation capability. e.g., vbscript won't let away with:
if not isnull(rs("myfield")) , rs("myfield") <> 0 ...
...because if rs("myfield") null, error in second condition, comparing null 0. i'll typically end doing instead:
dim myfield if isnull(rs("myfield")) myfield = 0 else myfield = rs("myfield") end if if myfield <> 0 ...
obviously, verboseness pretty appalling. looking around large code base, best workaround i've found use function original programmer wrote, called ternaryop, grafts in ternary operator-like functionality, i'm still stuck using temporary variable not necessary in more full-featured language. there better way? super-secret way short-circuiting exist in vbscript?
maybe not best way, works... also, if in vb6 or .net, can have different methods cast proper type too.
if cint( getval( rs("blah"), "" ) )<> 0 'do end if function getval( v, replacementval ) if v nothing getval = replacementval else getval = v end if end function
Comments
Post a Comment