Home

Visual Basic Built-In Functions: Len

  

The Memory Used by a Data Type

We know that different data types are used to store different values. To do that, each data type requires a different amount of space in the computer memory. To know the amount of space that a data type or a variable needs, you can call the Len() function.

Its syntax is:

Public Shared Function Len( _
   ByVal Expression As { Boolean | Byte | SByte | Char | Double |
   Integer | UInteger | Long | ULong | Object | Short | UShort |
   Single | String | DateTime | Decimal } _
) As Integer

To call this function, you can declare a variable with a data type of your choice and optionally initialize with the appropriate value, then pass that variable to the function. Here is an example:

Public Module Exercise

    Public Function Main() As Integer
        Dim Value As Integer

        Value = 774554

        MsgBox(Value & " needs " & Len(Value) & " bytes to be stored in memory.")
        Return 0
    End Function

End Module

This would produce:

Length

 
 
     
 

Home Copyright © 2008-2016, FunctionX, Inc.