enumerate user-defined data type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

An app I inherited has a bunch of user-defined data types. Is a user-defined
data type enumerable? And if so, how is it enumerated? I was hoping to use
a for-each loop to get to the name and value of each element in the data type.

thanks for looking, and even more thanks if you can help out.
 
Not directly, no. You could write a bunch of helper functions to convert the
UDTs to collections or arrays, for example ...

Public Type MyType
aLong As Long
aString As String
End Type

Public Function MyType2VariantArray(aType As MyType) As Variant

Dim work(1) As Variant

work(0) = aType.aLong
work(1) = aType.aString

MyType2VariantArray = work

End Function

Public Sub TestTypeToArray()

Dim theType As MyType
Dim theArray As Variant
Dim item As Variant

theType.aLong = 10
theType.aString = "some text"
theArray = MyType2VariantArray(theType)
For Each item In theArray
Debug.Print item
Next item

End Sub
 
Back
Top