VBScript conditional short-circuiting workaround

后端 未结 9 2090
心在旅途
心在旅途 2021-02-19 05:15

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

9条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 05:32

    Two options come to mind:

    1) use len() or lenb() to discover if there is any data in the variable:

    if not lenb(rs("myField"))=0 then...
    

    2) use a function that returns a boolean:

    if not isNothing(rs("myField")) then...
    

    where isNothing() is a function like so:

    function isNothing(vInput)
        isNothing = false : vInput = trim(vInput)
        if vartype(vInput)=0 or isEmpty(vInput) or isNull(vInput) or lenb(vInput)=0 then isNothing = true : end if 
    end function
    

提交回复
热议问题