LSet (statement)

Syntax 1

LSet dest = source

Syntax 2

LSet dest_variable = source_variable


Left-aligns the source string in the destination string or copies one user-defined type to another.


Syntax 1

The LSet statement copies the source string source into the destination string dest. The dest parameter must be the name of either a String or Variant variable. The source parameter is any expression convertible to a string.

If source is shorter in length than dest, then the string is left-aligned within dest, and the remaining characters are padded with spaces. If source$ is longer in length than dest, then source is truncated, copying only the leftmost number of characters that will fit in dest.

The destvariable parameter specifies a String or Variant variable. If destvariable is a Variant containing Empty, then no characters are copied. If destvariable is not convertible to a String, then a runtime error occurs. A runtime error results if destvariable is Null.

Syntax 2

The source structure is copied byte for byte into the destination structure. This is useful for copying structures of different types. Only the number of bytes of the smaller of the two structures is copied. Neither the source structure nor the destination structure can contain strings.


This example replaces a 40-character string of asterisks (*) with an RSet and LSet string and then displays the result.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  Dim msg,tmpstr$
  tmpstr$ = String(40,"*")
  msg1 = "Here are two strings that have been right-" + crlf
  msg1 = msg1 & "and left-justified in a 40-character string."
  Msg1 = msg1 & crlf & crlf
  Rset tmpstr$ = "Right|"
  msg1 = msg1 & tmpstr$ & crlf
  LSet tmpstr$ = "|Left"
  msg1 = msg1 & tmpstr$ & crlf
  MsgBox msg1
End Sub

See Also

RSet (function).

More information