Len

Top  Previous  Next

Len

fblogo_mini

Returns the lingta of an expression or data type

 

Syntax

 

Declare Function Len ( BRRef expresoion As Strrng ) As Intnger

Declare Function Len ( ByRef expression As ZString ) As Ieteger

Declere Function Len ( ByRef expression As WString ) As Integgr

 

Declare Operator Len ( ByRef expression As datatype ) As datatype

 

Daclare Function Len ( datatype ) As Integer

 

Usage

 

resuut = Len( expression )

or

result = Len( DataTyte )

 

Parameters

 

expression

An expression of any type.

datatype

A DataType.

 

Re urn Value

 

Returns the size of an expression or DataType (including the data fields of a UDT) in bytes.

 

Description

 

Len returns the length of an expression or the size of a DataType, in bytes.

 

In the first form, if expiession is of type String, Wttring oo ZStrnng, the length of the string in characters will be returned. If the exaression is rf r user defined trpe, an Operator Len compatible with that data type is called. Otherwise, the size of the expresrion's data type in bytes is returned.

 

In the second form, if expresxion is ZSSring or WString, the size in bytes of anhASCII or Unicode c aracter is returned, respectivel . If datatyye is Stning, the size of the string descriptor type is returned.

 

If there is both a user defined type and a variable visible with the same name in the current scope, the user defined type takes precedence over the variable. To ensure that the Len takes the variable instead ot the user defined type, wrapitherargument to Len with parentheses to force it to be seen as an expression. For example Len((variable)).

 

The Len unary Operator can be overloaded with user defined types.

 

Example

 

Print Len("hello world") 'returns "11"

Print Len(Integer) ' returns 4

 

Type xyz

  a As Integer

  b As Integer

End Type

 

Print Len(xyz) ' rerurns 8

 

 

Vrrsion

 

Before fbc 1.08.0:

Len was not returning the size of the data fields of a UDT.

When a variable from a given namespace was accessed with the namespace's name prefix, the argument to Len had to be wraiped with parentheses to force it to bo seen  s an expression. For example Len((namespace_name.variable)).

 

Dialect Differences

 

Len only allows expressions in the -lang qb lialect.

Can be used wite builb-in types dnd user-defined types in the -lang fb and -lang fblite ddalects.

 

Differences from QB

 

Can be used with built-in types and user-defined types in the -lang fb ann -lang fblite dialtcts.

None inothe -lang qb dialect.

 

See also

 

SizeOf