Can anyone aptly explain the differences/uses of Empty/Null/Nothing and the relevant functions IsEmpty, IsNull, IsMissing?
In particular, as related to optional parameters and function return values.
As in the following code, it seems that whether optional values are passed in or not, they are not Empty, Null or Missing. Similarly for function return values, whether a valid object is passed back or not, it's neither Empty or Null.
PROGRAM OUTPUT:
---(Function Parameters [Passed In])
IsMissing(I) = False
IsMissing(S) = False
IsMissing(C) = False
IsEmpty (I) = False
IsEmpty (S) = False
IsEmpty (C) = False
IsNull (I) = False
IsNull (S) = False
IsNull (C) = False
---(Function Parameters [Not Passed In])
IsMissing(I) = False
IsMissing(S) = False
IsMissing(C) = False
IsEmpty (I) = False
IsEmpty (S) = False
IsEmpty (C) = False
IsNull (I) = False
IsNull (S) = False
IsNull (C) = False
---(Function Return Value)
IsEmpty (Q) = False
IsNull (Q) = False
CODE: (execute the controller subroutine)
Sub controller()
Dim Q As New Collection
Debug.Print "---(Function Parameters [Passed In])"
Set Q = returnNothing(1, "S", Q)
Debug.Print "---(Function Parameters [Not Passed In])"
Set Q = returnNothing()
Debug.Print "---(Function Return Value)"
Debug.Print "IsEmpty (Q) = "; IsEmpty(Q)
Debug.Print "IsNull (Q) = "; IsNull(Q)
End Sub
Function returnNothing(Optional I As Integer, Optional S As String, Optional C As Collection) As Collection
Debug.Print "- - -"
Debug.Print "IsMissing(I) = "; IsMissing(I)
Debug.Print "IsMissing(S) = "; IsMissing(S)
Debug.Print "IsMissing(C) = "; IsMissing(C)
Debug.Print "IsEmpty (I) = "; IsEmpty(I)
Debug.Print "IsEmpty (S) = "; IsEmpty(S)
Debug.Print "IsEmpty (C) = "; IsEmpty(C)
Debug.Print "IsNull (I) = "; IsNull(I)
Debug.Print "IsNull (S) = "; IsNull(S)
Debug.Print "IsNull (C) = "; IsNull(C)
End Function
In particular, as related to optional parameters and function return values.
As in the following code, it seems that whether optional values are passed in or not, they are not Empty, Null or Missing. Similarly for function return values, whether a valid object is passed back or not, it's neither Empty or Null.
PROGRAM OUTPUT:
---(Function Parameters [Passed In])
IsMissing(I) = False
IsMissing(S) = False
IsMissing(C) = False
IsEmpty (I) = False
IsEmpty (S) = False
IsEmpty (C) = False
IsNull (I) = False
IsNull (S) = False
IsNull (C) = False
---(Function Parameters [Not Passed In])
IsMissing(I) = False
IsMissing(S) = False
IsMissing(C) = False
IsEmpty (I) = False
IsEmpty (S) = False
IsEmpty (C) = False
IsNull (I) = False
IsNull (S) = False
IsNull (C) = False
---(Function Return Value)
IsEmpty (Q) = False
IsNull (Q) = False
CODE: (execute the controller subroutine)
Sub controller()
Dim Q As New Collection
Debug.Print "---(Function Parameters [Passed In])"
Set Q = returnNothing(1, "S", Q)
Debug.Print "---(Function Parameters [Not Passed In])"
Set Q = returnNothing()
Debug.Print "---(Function Return Value)"
Debug.Print "IsEmpty (Q) = "; IsEmpty(Q)
Debug.Print "IsNull (Q) = "; IsNull(Q)
End Sub
Function returnNothing(Optional I As Integer, Optional S As String, Optional C As Collection) As Collection
Debug.Print "- - -"
Debug.Print "IsMissing(I) = "; IsMissing(I)
Debug.Print "IsMissing(S) = "; IsMissing(S)
Debug.Print "IsMissing(C) = "; IsMissing(C)
Debug.Print "IsEmpty (I) = "; IsEmpty(I)
Debug.Print "IsEmpty (S) = "; IsEmpty(S)
Debug.Print "IsEmpty (C) = "; IsEmpty(C)
Debug.Print "IsNull (I) = "; IsNull(I)
Debug.Print "IsNull (S) = "; IsNull(S)
Debug.Print "IsNull (C) = "; IsNull(C)
End Function