Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript conditional short-circuiting workaround

I have a large classic ASP app that I have to maintain, and I repeatedly find myself thwarted by the lack of short-circuit evaluation capability. E.g., VBScript won't let you get away with:

if not isNull(Rs("myField")) and Rs("myField") <> 0 then
...

...because if Rs("myField") is null, you get an error in the second condition, comparing null to 0. So I'll typically end up doing this instead:

dim myField
if isNull(Rs("myField")) then 
    myField = 0
else
    myField = Rs("myField")
end if

if myField <> 0 then
...

Obviously, the verboseness is pretty appalling. Looking around this large code base, the best workaround I've found is to use a function the original programmer wrote, called TernaryOp, which basically grafts in ternary operator-like functionality, but I'm still stuck using a temporary variable that would not be necessary in a more full-featured language. Is there a better way? Some super-secret way that short-circuiting really does exist in VBScript?

like image 724
Kevin Crumley Avatar asked Sep 12 '08 17:09

Kevin Crumley


1 Answers

Nested IFs (only slightly less verbose):

if not isNull(Rs("myField")) Then
   if Rs("myField") <> 0 then
like image 199
busse Avatar answered Sep 16 '22 14:09

busse