O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Left, LeftB Functions

Syntax

Left(string, length)
string

Use: Required

Data Type: String

The string to be processed.

length

Use: Required

Data Type: Long

The number of characters to return from the left of the string.

Return Value

Left and LeftB return a String.

Description

Returns a string containing the left-most length characters of string.

Rules at a Glance

  • If length is 0, a zero-length string (” “) is returned.

  • If length is greater than the length of string, string is returned.

  • If length is less than 0 or Null, the function generates runtime error 5, “Invalid procedure call or argument,” and runtime error 94, “Invalid use of Null,” respectively.

  • If string contains Null, Left returns Null.

  • Left processes strings of characters; LeftB is used to process binary data.

Programming Tips and Gotchas

  • Use the Len function to determine the overall length of string.

  • When you use the LeftB function with byte data, length specifies the number of bytes to return.

VBScript/VB & VBA Differences

There are no Left$ or LeftB$ functions available in VBScript.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required