I keep getting this error in one of my scripts:
Object not collection
So, I would like to create a function that checks if an object is a collection before performing any operations on it.
So far I have created this:
Function IsCollection(param) If IsEmpty(param) Then IsCollection = False ElseIf(TypeName(param) = "String") Then IsCollection = False Else IsCollection = True End If End Function
But I feel like I am missing some checks - for sure, only the available types are not just String
, Empty
or Collection
?
I thought it was better to just try and list param
, and if that returns an error, then I know that the output is false
- does this seem like the best alternative?
Function IsCollection(param) For Each p In param ' Anything need to go here? Next If Err > 0 Then IsCollection = False Else IsCollection = True End If End Function
Even in the second example, it would be reasonable to indicate whether this error is: "The object is not a collection"?
source share