I needed to be able to enumerate through the members of a large UDT to compare them with each other. Since VB has no way to do this I created my own and though others may care.

Only works with variants.
VB Code:
  1. Public Type Test2
  2.     aa As Variant
  3.     bb As Variant
  4.     cc As Variant
  5.     dd As Variant
  6.     ee As Variant
  7. End Type
  8.  
  9. 'Copy Memory Func
  10. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByVal pSource As Any, ByVal Length As Long)
  11.  
  12. 'VB own TypeName func, need to pass pointer
  13. Public Declare Function rTypeName Lib "MSVBVM60.dll" Alias "rtcTypeName" (ByVal SS As Any) As String
  14.  
  15. '************************
  16. 'In: pass TWO vaptr(UDTvariable) 's to func call with size of UDT
  17. 'Out: String
  18. Public Function CompareUDTs(UDTptr1 As Long, UDTptr2 As Long, UDTSize As Long) As String
  19. Dim retString As String
  20. Dim tempString As String
  21. Dim StringPtr As Long
  22. Dim i As Long
  23. Dim VariantType1 As String
  24. Dim VariantType2 As String
  25. Dim tempVariant1 As Variant
  26. Dim tempVariant2 As Variant
  27.     Debug.Print UDTSize
  28.     'each variant is 16 bytes long
  29.     For i = 0 To UDTSize - 16 Step 16
  30.         'lets determine the variant type for the fun of it
  31.         VariantType1 = Replace(rTypeName(UDTptr1 + i), vbNullChar, "")
  32.         VariantType2 = Replace(rTypeName(UDTptr2 + i), vbNullChar, "")
  33.         Debug.Print VariantType1, VariantType2
  34.         'now copy the current variant to the tempvariant
  35.         CopyMemory tempVariant1, UDTptr1 + i, 16
  36.         CopyMemory tempVariant2, UDTptr2 + i, 16
  37.         Debug.Print ":" & tempVariant1, tempVariant2
  38.         If tempVariant1 = tempVariant2 Then
  39.             retString = retString & "Equal" & vbCrLf
  40.         Else
  41.             retString = retString & "Not Equal" & vbCrLf
  42.         End If
  43.     Next i
  44.     Debug.Print retString
  45.     CompareUDTs = retString
  46. End Function
  47.  
  48. '****on FORM
  49. Private Sub Command1_Click()
  50. Dim ff As Test2
  51. Dim cc As Test2
  52. Dim aString As String
  53.     ff.aa = "1"
  54.     ff.bb = 200
  55.     ff.cc = "a"
  56.     ff.dd = 1
  57.     ff.ee = 839
  58.    
  59.     cc.aa = "0923"
  60.     cc.bb = 200
  61.     cc.cc = "a"
  62.     cc.dd = 10
  63.     cc.ee = 839
  64.    
  65.     aString = CompareUDTs(VarPtr(ff), VarPtr(cc), Len(ff))
  66.     Text1.Text = aString
  67. End Sub