This article introduces the sources and judgment methods of NULL, Empty, and Nothing in ASP. Hope it helps everyone.
This article introduces the sources and judgment methods of NULL, Empty, and Nothing in ASP.
Dim A
Dim B As String
Dim C As Integer
Dim D As Object
A is equal to Empty, because "indeterminate variables" that have not been initialized are equal to Empty. But if you detect A = or A = 0, you can also get a True value.
B is equal, because uninitialized non-fixed-length "strings" are equal. But please note B <> Null.
C is equal to 0. Is there still a problem with this?
D is equal to Nothing, and "object variables" that have not been set with objects are equal to Nothing, but please do not use D = Nothing, but use D Is Nothing to determine whether D is equal to Nothing, because the symbol for determining equality is Is, not =.
The most confusing part is the reserved word Null. Please see the following statement:
Print X = Null
Print X <> Null
The result is Null (not True or False). This is because as long as any operation expression contains Null, the operation expression is equal to Null. In fact, if you want to judge whether a certain data is Null, you must not use:
If X = Null Then ' will always get Null
Instead use:
If IsNull(X) Then
Which kind of data will be equal to Null? In addition to containing Null operators, "data fields" (in the database) that do not enter any data will be equal to Null. That is, everyone can understand that Null is the empty field read out from the data.