Set
is assigning a new reference to the AST
variable, rather than assigning a value to (the object currently referenced by AST
)'s default property.
There's not much VB 6 documentation around on the web, but1 some of the help for VB.Net still references the older ways.
See Default Property Changed for Visual Basic 6 Users:
In Visual Basic 6.0, default properties are supported on objects. On a Label control, for example, Caption is the default property, and the two assignments in the following example are equivalent.
Dim lbl As Label
lbl = "Important"
lbl.Caption = "Important"
While default properties enable a certain amount of shorthand in writing Visual Basic code, they have several drawbacks:
...
- Default properties make the Set statement necessary in the Visual Basic language. The following example shows how Set is needed to indicate that an object reference, rather than a default property, is to be assigned.
Dim lbl1 As Label, lbl2 As Label
lbl1 = "Saving" ' Assign a value to lbl1's Caption property.
lbl2 = lbl1 ' Replace lbl2's Caption property with lbl1's.
Set lbl2 = lbl1 ' Replace lbl2 with an object reference to lbl1.
So, in VB.Net, Let
and Set
became obsolete (in fact, Let
was already pretty much obsolete in VB 6) because the language rules changed. An assignment A = B
, if A
is a reference, is always assigning a new reference to A
.
1MarkJ has supplied links to the older VB6 documentation in the comments.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…