Results 1 to 16 of 16

Thread: [RESOLVED] Hacking Variant

Threaded View

  1. #1

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Resolved [RESOLVED] Hacking Variant

    I'm trying to understand the data structure of the VB variant data type and am getting a puzzling result:

    VB Code:
    1. Sub VariantTest()
    2.     Dim vA(1 To 2) As Variant
    3.     Dim A(1 To 2) As Double, d1 As Double, d2 As Double
    4.     Dim vB As Variant
    5.     Dim itype As Integer
    6.    
    7.     A(1) = 0.35
    8.     A(2) = 0.07
    9.     vA(1) = A(1)
    10.     vA(2) = A(2)
    11.    
    12.     vB = vA
    13.     CopyMemory itype, vB(1), 2                  'get the variant descriptor type
    14.     CopyMemory d1, ByVal VarPtr(vB(1)) + 8, 8   'get 1st value
    15.     CopyMemory d2, ByVal VarPtr(vB(1)) + 24, 8  'get 2nd value
    16.     Debug.Print TypeName(vB), itype, d1, d2     'Variant() 5 0.35 0.07
    17.    
    18.     vB = A
    19.     CopyMemory itype, vB(1), 2                  'get the variant descriptor type
    20.     CopyMemory d1, ByVal VarPtr(vB(1)) + 8, 8   'get 1st value
    21.     CopyMemory d2, ByVal VarPtr(vB(1)) + 24, 8  'get 2nd value
    22.     Debug.Print TypeName(vB), itype, d1, d2     'Double() 16389 3.75776923216955E-316 0
    23. End Sub
    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.

    Can someone explain what's going on?
    Last edited by VBAhack; Jun 2nd, 2008 at 01:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width