Results 1 to 7 of 7

Thread: Variant?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    81
    Hi all,

    I need to know what is the default space occupied by a variant variable and its size?

    And waht will be its space and size when u assign some value to the variant variable.
    Pls reply ASAP.

    Luv...........Ravindran

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Location
    Qc, Canada
    Posts
    70
    Hi,

    A variant with a numeric value takes 16 bytes, with a string, takes 22 bytes + string lenght.

    Steph
    Virtually Impossible !

    VB5 Entreprise (SP3) - VB6 Entreprise (SP4), MSSQL7, MSAccess, VBA, VBScript, ASP

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    You can use the Len function to retrieve this information..

    Code:
    Private Sub Form_Load()
        Dim v As Variant
        
        Debug.Print Len(v) ' returns 0
        
        v = 15
        
        Debug.Print Len(v) ' returns 2 (integer)
        
        v = "JON"
        
        Debug.Print Len(v) ' returns 3
        
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Better yet use the LenB function....

    Code:
    Private Sub Form_Load()
        Dim v As Variant
        
        Debug.Print LenB(v) 
        
        v = 15
        
        Debug.Print LenB(v) 
        
        v = "JON"
        
        Debug.Print LenB(v) 
        
    End Sub
    and I think steph meant that an integer value is 16 bits and 2 bytes.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    No, a variant is always that fat 16 byte, 128 bit, and for strings 22 bytes + string length * 2 bytes
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    WOW! That SUCKS!!

    So then the best advice would be to not use Variants?
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  7. #7
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    London
    Posts
    290
    >So then the best advice would be to not use Variants?

    Yeah, if you know what type of data you`ll be dealing with, then using the appropriate type is faster and smaller.

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