Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Len Function

Class

Microsoft.VisualBasic.Strings

Syntax

Len(expression)
expression (required; any)

Any valid variable name or expression

Return Value

Integer

Description

Counts the number of characters within a string or the size of a given variable

Rules at a Glance

  • If expression contains Nothing, Len returns 0.

  • For a string or String variable, Len returns the number of characters in the string.

  • For a nonobject and nonstructure variable, Len returns the number of bytes required to store the variable in memory.

  • For a variable of type Object, Len returns the length of its data subtype. If the object is uninitialized, its length is 0. However, if the object contains a strongly typed class instance, an InvalidCastException exception is thrown.

  • For a structure, Len returns the number of bytes required to store the structure as a file. (But see the comment in Section .)

  • For a strongly typed object variable, such as one defined by the Class... End Class construct, Len generates an InvalidCastException exception.

  • If varname is an array, you must also specify a valid subscript. In other words, Len cannot be used to determine the total number of elements in or the total size of an array.

Programming Tips and Gotchas

  • Len cannot accurately report the number of bytes required to store structures that contain variable-length strings. If you need to know how many bytes of storage space will be required by a structure that includes string members, you can fix the length of the strings by using the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata