Posts

Showing posts with the label variant

Write result of function to a variable, where result could be an object

Write result of function to a variable, where result could be an object If I have a function which may return an object or a primitive type - within it I can do the following to handle those two cases: Function Result() As Variant 'may be object or not '... get item - the return value If IsObject(item) Then Set Result = item Else Result = item End If End Function However, how can I do the same test for the variable where Result is stored without running the function two times? Eg Result Dim myResult As Variant If IsObject(Result) Then 'test return type of function Set myResult = Result Else myResult = Result End If As myResult = Result 'fails if Result returns object Set myResult = Result 'fails if Result returns non-object I am trying to write a series of objects/non objects to an array of variant type I'm curious about the specifics where you wouldn't know what was being returned. In theo...