LSet Statement

Syntax

LSet stringvar = string

stringvar

Use: Required

Data Type: String

The name of a string variable to receive the string.

string

Use: Required

Data Type: String

A string expression to be copied into stringvar.

Description

Copies string into stringvar, left-aligning string within stringvar.

Rules at a Glance

  • LSet has meaning only when used with fixed-length strings.

  • If the length of string is less than that of stringvar, the extra characters within stringvar are padded with spaces.

  • If the length of string is greater than that of stringvar, string is truncated to the length of stringvar.

Programming Tips and Gotchas

  • LSet and RSet are legacies from the pre-Visual Basic days of BASIC. LSet doesn't really need to be used at all, since the same result can be accomplished with a simple assignment operation to either a fixed-length string or a variable-length string.

  • Although its use is unnecessary, LSet does appear to yield some performance benefit in comparison to assignment statements. When LSet copies a string of approximately 70 characters to a variable-length string, it executes approximately 33% faster than a simple assignment statement. When copying the same string to a fixed-length string, it offers approximately a 25% performance gain.

  • According to the Visual Basic documentation, you can also use the LSet statement to copy a variable of one user-defined type to a variable of another user-defined type. In fact, the Microsoft VB5 help section goes so far as ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.