I'm trying to understand the data structure of the VB variant data type and am getting a puzzling result:
If vB is assigned to the variant array (of doubles), the resulting data structure makes perfect sense. But, if vB is assigned to the array of doubles, the variant data structure makes no sense at all. The descriptor type is 16389 and I can't find the data values anywhere.VB Code:
Sub VariantTest() Dim vA(1 To 2) As Variant Dim A(1 To 2) As Double, d1 As Double, d2 As Double Dim vB As Variant Dim itype As Integer A(1) = 0.35 A(2) = 0.07 vA(1) = A(1) vA(2) = A(2) vB = vA CopyMemory itype, vB(1), 2 'get the variant descriptor type CopyMemory d1, ByVal VarPtr(vB(1)) + 8, 8 'get 1st value CopyMemory d2, ByVal VarPtr(vB(1)) + 24, 8 'get 2nd value Debug.Print TypeName(vB), itype, d1, d2 'Variant() 5 0.35 0.07 vB = A CopyMemory itype, vB(1), 2 'get the variant descriptor type CopyMemory d1, ByVal VarPtr(vB(1)) + 8, 8 'get 1st value CopyMemory d2, ByVal VarPtr(vB(1)) + 24, 8 'get 2nd value Debug.Print TypeName(vB), itype, d1, d2 'Double() 16389 3.75776923216955E-316 0 End Sub
Can someone explain what's going on?





Reply With Quote