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 to include the syntax for this (although the online documentation for VB6 explicitly warns against this practice). However, copying the data from one data type into the memory space of a different data type is a recipe for disaster in any programming language. Basically, what happens behind the scenes is that the raw binary is copied from one memory location to another. This means that the individual data types of the elements within the user-defined types are completely ignored. When you then access the data in the copied user-defined type, the information it holds is, at best, useless. If you must copy (and in the process translate) one user-defined data structure to another, do this using assignment statements on an element-by-element basis.

See Also

RSet Statement
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.20.236