LSet Statement

See Also1GP70XG              Example3MEIHW>Low

Left aligns a string within the space of a string variable or copies a variable of one user-defined type to another variable of a different user-defined type.

Syntax 1

LSet stringvar = stringexpr

Syntax 2

LSet variable1 = variable2

Remarks

The LSet statement has these parts:

Part               Description

 

stringvar        Name of a String variable.

stringexpr      String expression1330R89 to be left aligned within stringvar.

variable1        Name of the user-defined type variable being copied to.

variable2        Name of the user-defined type variable being copied from.

 

If stringexpr is shorter than stringvar, LSet left aligns stringexpr within stringvar.  LSet replaces any leftover characters in stringvar with spaces.

If stringexpr is longer than stringvar, LSet places only the leftmost characters, up to the length of the stringvar, in stringvar.  Characters beyond the length of stringvar are truncated from the right.

Use LSet with Syntax 2 to assign one user-defined type variable to another.  The following example copies the contents of RecTwo (a user-defined type variable) to RecOne (a variable of another user-defined type):

   Type TwoString

      StrFld As String * 2

   End Type

 

   Type ThreeString

      StrFld As String * 3

   End Type

   Dim RecOne As TwoString, RecTwo As ThreeString

 

   LSet RecOne = RecTwo

 

Because RecOne is 2 bytes long, only 2 bytes are copied from RecTwo.  LSet copies only the number of bytes in the shorter of the two user-defined type variables.

You can't use LSet to copy variables of different user-defined types if either contains a variable-length string or a Variant8PHEAW3.


See Also

RSet Statement103L0PY


LSet Statement Example

The example uses LSet to left align text in a 40-character String variable).  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Msg, NL, OldFont, TmpStr          ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   OldFont = FontName                    ' Save old font.

   FontName = "Courier"                  ' Use monospaced font

   TmpStr = String(40, "*")              ' Create 40-character string.

   Msg = "Here are two strings that have been right"

   Msg = Msg & NL & "and left justified in a " & Len(TmpStr)

   Msg = Msg & "-character string." & NL & TmpStr & NL

   RSet TmpStr = "Right->"               ' Right justify.

   Msg = Msg & TmpStr & NL

   LSet TmpStr = "<-Left"                ' Left justify.

   Msg = Msg & TmpStr & NL

   Print Msg                             ' Display message.

   FontName = OldFont                    ' Restore original font.

End Sub