Why is this function compared to an arbitrary number as a null check?

I came across this interesting feature in the ASP Classic part that I support. At first I laughed, shook my head, then cried (only a little). But then I started wondering if there was any legitimate reason why 999999999999999 would apparently be considered NULL, since VBScript has its own quirks. As mentioned in the comments, the values ​​passed to this function are returned from the dll COM.

Can anyone confirm if there is any legitimate reason for this or has he matured to be sent to TheDailyWTF.

function NullNumberCheck(Value) if IsNumeric(Value) then if Value = 999999999999999 then Value = "" end if end if NullNumberCheck = Value end function 
+4
source share
3 answers

This is similar to the case of “magic zero” in the data source - is there a column in the database that supports the values ​​passed to this function, which cannot be null?

Why do people use magic values ​​instead of zero in their code?

+2
source

The author uses this as a method to clear or undo this variable. By setting Value to an empty string, it deletes any previous value. An author could just as easily set it to 0, vbNull or vbEmpty. It really depends on what you do with the value later in the script. If you continue to perform additional checks on the variable, setting it to vbNull may not be practical and setting it to vbEmpty may cause your script to crash if you use Option Explicit.

So, to answer your question, no, this is an invalid way to check the value "null", because it is not a comparison operation at all, it performs the assignment of a variable.

+1
source

To check for a null value, you can use the IsNull function built into VBscript

http://www.w3schools.com/vbscript/func_isnull.asp

0
source

Source: https://habr.com/ru/post/1391296/


All Articles