Results 1 to 6 of 6

Thread: Size Of Variable?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Question

    Hi,
    How do you get/return the size of a variable or object in
    bytes.

    Code:
    example : 
    
    Public Sub Test
     Dim Name as String
     Dim Value as Long
    
     Name = "John Black"
     Value = SizeOf(Name)
     
    End Sub
    Omar
    [email protected]
    http://omar.caribwalk.com
    To God Be The Glory

    I see Tech People ...

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    see help on LEN keyword

  3. #3
    Guest
    It's actually the Len function, not keyword .

    It is used like this:

    Code:
    Dim Name As String
    Dim Value As Long
    Name = "John Black"
    Value = Len(Name)
    Debug.Print Value

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Question Interger and Arrays

    Will this work for Integers and Array?
    Omar
    [email protected]
    http://omar.caribwalk.com
    To God Be The Glory

    I see Tech People ...

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here is Data Type Summary from MSDN:
    Code:
    Byte 1 byte 
    Boolean 2 bytes 
    Integer 2 bytes 
    Long 4 bytes 
    Single 4 bytes 
    Double 8 bytes 
    Currency 8 bytes 
    Decimal 14 bytes 
    Date 8 bytes 
    Object 4 bytes (Any Object reference) 
    String (variable-length) 10 bytes + string length 0 to approximately 2 billion  
    String (fixed-length) Length of string 1 to approximately 65,400 
    Variant (with numbers) 16 bytes Any numeric value up to the range of a Double 
    Variant (with characters) 22 bytes + string length Same range as for variable-length String 
    User-defined (using Type) Number required by elements The range of each element is the same as the range of its data type.

    Arrays of any data type require 20 bytes of memory plus 4 bytes for each array dimension plus the number of bytes occupied by the data itself. The memory occupied by the data can be calculated by multiplying the number of data elements by the size of each element. For example, the data in a single-dimension array consisting of 4 Integer data elements of 2 bytes each occupies 8 bytes. The 8 bytes required for the data plus the 24 bytes of overhead brings the total memory requirement for the array to 32 bytes.

    A Variant containing an array requires 12 bytes more than the array alone.


  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    LenB will return the exact size in bytes for UDT's and Variants.
    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.

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