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?
Maybe not the best way, but it certainly works… Also, if you are in vb6 or .net, you can have different methods that cast to proper type too.