Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 358
- Office Version
- 2003 or older
- Platform
- Windows
The function is supposed to return TRUE or FALSE indicating whether all the elements in the array have the default value for the particular data type. Depending on the data type of the array, the default value may be vbNullString, 0, Empty, or Nothing.
But, i am getting a False with, for e.g., vArr(1 to 3) As Variant or with dArr(1 to 3) As Double with Arr(1)=3, Arr(2)=2, Arr(3)=1. Any reason why?
But, i am getting a False with, for e.g., vArr(1 to 3) As Variant or with dArr(1 to 3) As Double with Arr(1)=3, Arr(2)=2, Arr(3)=1. Any reason why?
VBA Code:
Public Function IsArrayAllDefault(InputArray As Variant) As Boolean
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IsArrayAllEmpty
' Returns True if the array contains all default values for its
' data type:
' Variable Type Value
' ------------- -------------------
' Variant Empty
' String vbNullString
' Numeric 0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Ndx As Long
Dim DefaultValue As Variant
'''''''''''''''''''''''''''''''
' Set the default return value.
'''''''''''''''''''''''''''''''
IsArrayAllDefault = False
'''''''''''''''''''''''''''''''''''
' Ensure InputArray is an array.
'''''''''''''''''''''''''''''''''''
If IsArray(InputArray) = False Then
IsArrayAllDefault = False
Exit Function
End If
''''''''''''''''''''''''''''''''''
' Ensure array is allocated. An
' unallocated is considered to be
' all the same type. Return True.
''''''''''''''''''''''''''''''''''
If IsArrayAllocated(Arr:=InputArray) = False Then
IsArrayAllDefault = True
Exit Function
End If
''''''''''''''''''''''''''''''''''
' Test the type of variable
''''''''''''''''''''''''''''''''''
Select Case VarType(InputArray)
Case vbArray + vbVariant
DefaultValue = Empty
Case vbArray + vbString
DefaultValue = vbNullString
Case Is > vbArray
DefaultValue = 0
End Select
For Ndx = LBound(InputArray) To UBound(InputArray)
If IsObject(InputArray(Ndx)) Then
If Not InputArray(Ndx) Is Nothing Then
Exit Function
Else
End If
Else
If VarType(InputArray(Ndx)) <> vbEmpty Then
If InputArray(Ndx) <> DefaultValue Then
Exit Function
End If
End If
End If
Next Ndx
'''''''''''''''''''''''''''''''
' If we make it out of the loop,
' the array is all defaults.
' Return True.
'''''''''''''''''''''''''''''''
IsArrayAllDefault = True
End Function