In VBA-heritage VB and ignoring custom classes and property definitions, Let
was used for value assignment and Set
was used for reference assignment. I don't know for certain, but I would speculate that the reason for the distinction was to disambiguate in the presence of default properties. In VBA, if I write
foo = bar
If foo
and bar
are both object types, this line could refer to both a reference assignment (change foo
to refer to the same underlying object as bar
) or a value assignment (assign the value of the default property of bar
to the default property of foo
). Introducing Set
as an alternative to the default Let
allows both to be handled:
Let foo = bar
Set foo = bar
With Let
we do the default property value assignment, with Set
we do the reference assignment. (Let
was long since made optional, so foo = bar
would be equivalent to Let foo = bar
.)
The customized Property Let
and Property Set
would follow from this language behavior, and ideally implementations would act like the native language features, although the answers on the question reference in the comments (here: https://stackoverflow.com/a/5042718) point to some interesting things that users may have done with the additional flexibility given by two different assignment keywords.
.NET VB has discontinued default properties except for indexing, so the statement foo = bar
is unambiguous: if foo
is a value type, then it does value assignment, and if foo
is a reference type, it does reference assignment. Thus, the Set
statement has gone away, but for whatever reason, they preferred to retain the assignment side of a custom property as Set
instead of Let
. I don't know what the thinking was; in my experience, a custom assignment is as likely to be value-based as it is reference-based, so it isn't necessarily the case that keeping Set
is more in line with the equivalent VBA code.
Specifically to your question, you would replace the custom Property Let
with a custom Set
block inside a property, i.e.
Public Property Base(ByVal N As Integer) As String
Get
'...
'Can be omitted and property can be WriteOnly if desired
End Get
Private Set(ByVal value As String)
Dim pos As Integer
pos = InStr(value, " ")
If pos > 0 Then
cond1(N) = Left(value, pos - 1)
cond2(N) = Right(value, Len(value) - pos - 1)
Else
cond1(N) = value
End If
End Set
End Property
(I think the code would work as-is, but I would probably rewrite it to use the .NET string handling functions instead of the legacy VBA functions.)