1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! # `RSet` Statement
//!
//! Right-aligns a string within a string variable or copies one user-defined variable to another.
//!
//! ## Syntax
//!
//! ```vb
//! RSet stringvar = string
//! RSet varname1 = varname2 ' For user-defined types
//! ```
//!
//! ## Parts
//!
//! - **stringvar**: Required. String variable or property name to be right-aligned.
//! - **string**: Required. String expression to be right-aligned within stringvar.
//! - **varname1**: Required. Variable of a user-defined type.
//! - **varname2**: Required. Variable of a different user-defined type.
//!
//!
//! ## Remarks
//!
//! - **String Alignment**: When used with string variables, `RSet` right-aligns the string within
//! the variable. If the string is shorter than the variable, spaces are added on the left to
//! achieve right alignment.
//! - **Fixed-Length Strings**: `RSet` is particularly useful with fixed-length strings where you
//! need to right-justify text within a specific width.
//! - **User-Defined Types**: When used with user-defined types (UDTs), `RSet` copies data from one
//! variable to another on a byte-by-byte basis. This can be useful for converting between
//! different UDT structures that have the same size.
//! - **Shorter Strings**: If the source string is shorter than the target variable, spaces are
//! added on the left side to right-align the text.
//! - **Longer Strings**: If the source string is longer than the target variable, the string is
//! truncated on the left side, keeping only the rightmost characters that fit.
//! - **Comparison to `LSet`**: `RSet` is the opposite of `LSet`. While `LSet` left-aligns strings,
//! `RSet` right-aligns them.
//!
//! ## Example
//!
//! ```vb
//! Dim MyString As String * 10
//! MyString = String(10, "X") ' Fill with X's
//! RSet MyString = "VB6" ' Result: " VB6"
//! ```
//!
//! ## Example with User-Defined Types
//!
//! ```vb
//! Type TypeA
//! Name As String * 20
//! Age As Integer
//! End Type
//!
//! Type TypeB
//! Data As String * 22
//! End Type
//!
//! Dim VarA As TypeA
//! Dim VarB As TypeB
//!
//! VarA.Name = "John"
//! VarA.Age = 30
//! RSet VarB = VarA ' Copy VarA to VarB byte-by-byte
//! ```
//!
//! ## See Also
//!
//! - `LSet` statement (left-align strings)
//! - `Mid` statement (replace characters in a string)
//! - Fixed-length string variables
//!
//! ## References
//!
//! - [RSet Statement (Visual Basic 6.0)](https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa266258(v=vs.60))
use VBResult;
use crateVBString;
/// Right-aligns `string` within `stringvar`, returning the aligned result.
///
/// If `string` is shorter than `stringvar`, it is padded with spaces on the
/// left; if it is longer, only the rightmost characters that fit are kept.
/// The width used is the current length of `stringvar`, which mirrors a
/// fixed-length string's declared size when callers track it.
///
/// # Errors
///
/// Never fails for string operands; returns `VBResult` for consistency with
/// the statement surface (user-defined-type copies may fail in the future).