VB6关键字Set是什么意思? [英] VB6 keyword Set what does it mean?

查看:42
本文介绍了VB6关键字Set是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了一个旧的 VB6 代码,我看到了这样的东西

 Set AST = CreateObject("ADODB.Stream")

我有使用 VB6 和 VB.NET 的经验,但我以前从未在我的 VB6 项目中使用过这个关键字 Set.我在网上查了很多Set的用法,我只知道Properties的用法,只有我在VB.NET中知道

公共属性 myProperty As String得到返回 _myProperty结束获取设置(值作为字符串)_myProperty = 值结束集最终财产

而且我认为 Set 在上面的代码中使用不同.这两种方法有什么区别?我想知道 Set 在 VB6 中的作用

解决方案

Set 正在为 AST 变量分配一个新的引用,而不是为(AST) 的默认属性当前引用的对象.

<小时>

网络上没有太多的 VB 6 文档,但是1 VB.Net 的一些帮助仍然引用了旧的方法.

请参阅 为 Visual Basic 6 更改的默认属性用户:

<块引用>

在 Visual Basic 6.0 中,对象支持默认属性.例如,在 Label 控件上,Caption 是默认属性,下面示例中的两个赋值是等效的.

将 lbl 变暗作为标签lbl = "重要"lbl.Caption = "重要"

<块引用>

虽然默认属性在编写 Visual Basic 代码时启用了一定数量的速记,但它们有几个缺点:

...

  • 默认属性使 Set 语句在 Visual Basic 语言中成为必需.以下示例显示了如何需要 Set 来指示要分配的对象引用而不是默认属性.

将 lbl1 作为标签,lbl2 作为标签lbl1 = "Saving" ' 为 lbl1 的 Caption 属性赋值.lbl2 = lbl1 ' 将 lbl2 的 Caption 属性替换为 lbl1 的.Set lbl2 = lbl1 ' 用对 lbl1 的对象引用替换 lbl2.

<小时>

所以,在 VB.Net 中,LetSet 已经过时了(事实上,Let 在 VB 6 中已经过时了)因为语言规则变了.一个赋值A = B,如果A是一个引用,总是给A分配一个新的引用.

<小时>

1MarkJ 在评论中提供了旧版 VB6 文档的链接.

I been browsing an old VB6 code and I saw something like this

 Set AST = CreateObject("ADODB.Stream")

I have experience using VB6 and VB.NET but I never use this keyword Set before in my VB6 projects. I researched a lot in the internet what is the use of Set and what I only know is the usage in Properties which is only I know in VB.NET

Public Property myProperty As String
    Get
      Return _myProperty
    End Get
    Set(value as String)
      _myProperty = value
    End Set
End Property

and I think Set is used differently on the code above. What is the difference of the two approaches? I want to know what does the Set do in VB6

解决方案

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.

这篇关于VB6关键字Set是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆