RSet

Right-aligns a string within a string variable.

Syntax:

RSet stringvar = string

stringvar
Name of a string variable.
string
String expression to be right-aligned within stringvar.

If stringvar is longer than string, RSet replaces any leftover characters in stringvar with spaces, back to its beginning.

If string is longer than stringvar, RSet places only the leftmost characters, up to the length of stringvar, in stringvar. The rightmost characters of string are the ones dropped, as with LSet.

RSet never changes the length of stringvar, so a stringvar of zero length stays empty. stringvar can be a variable-length string, a fixed-length string, or a Variant that holds a string. A string that is Null raises error 94.

A Variant stringvar that holds a number, a date or a Boolean is aligned within the text of its value, which becomes its new value: one that holds True has the four characters of True. One that holds Null raises error 94.

Dim v As Variant
v = True
RSet v = "ab"
Debug.Print "[" & v & "]"   ' [  ab]

Note BETA 1042

A Variant stringvar that holds an object raises error 13, Type mismatch. VB6 raises error 450, Wrong number of arguments or invalid property assignment.

Note

RSet can’t be used with user-defined types. The compiler refuses the statement.

Example

This example uses the RSet statement to right-align a string within a string variable.

Dim MyString
MyString = "0123456789"   ' Initialize string.
RSet MyString = "Right->" ' MyString contains "   Right->".

This example shows the padding, the truncation, a fixed-length string and an empty destination.

Dim s As String
Dim fixed As String * 5
s = "0123456789"
RSet s = "ab"
Debug.Print "[" & s & "]"        ' [        ab]
RSet s = "abcdefghijklm"
Debug.Print "[" & s & "]"        ' [abcdefghij]
fixed = "01234"
RSet fixed = "ab"
Debug.Print "[" & fixed & "]"    ' [   ab]
s = ""
RSet s = "abc"
Debug.Print Len(s)               ' 0

See Also