LSet statement
Left aligns a string within a string variable, or copies a variable of one user-defined type to another variable of a different user-defined type.
Syntax
LSet stringvar = string
LSet varname1 = varname2
The LSet statement syntax has these parts:
Part | Description |
---|---|
stringvar | Required. Name of string variable. |
string | Required. String expression to be left-aligned within stringvar. |
varname1 | Required. Variable name of the user-defined type being copied to. |
varname2 | Required. Variable name of the user-defined type being copied from. |
Remarks
LSet replaces any leftover characters in stringvar with spaces.
If string is longer than stringvar, LSet places only the leftmost characters, up to the length of the stringvar, in stringvar.
Using LSet to copy a variable of one user-defined type into a variable of a different user-defined type is not recommended. Copying data of one data type into space reserved for a different data type can cause unpredictable results.
When you copy a variable from one user-defined type to another, the binary data from one variable is copied into the memory space of the other, without regard for the data types specified for the elements.
Example
This example uses the LSet statement to left align a string within a string variable. Although LSet can also be used to copy a variable of one user-defined type to another variable of a different, but compatible, user-defined type, this practice is not recommended. Due to the varying implementations of data structures among platforms, such a use of LSet can't be guaranteed to be portable.
Dim MyString
MyString = "0123456789" ' Initialize string.
Lset MyString = "<-Left" ' MyString contains "<-Left ".
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.