首页 > 解决方案 > 局部变量优先于属性?

问题描述

我正在研究一些 VB6,它在类定义中有一些代码,归结为:-

Private intMyValue as Integer

Public Property Get MyValue as Integer
    MyValue = intMyValue
End Property

Public Sub DoFoo (ByVal MyValue As Integer)
    Dim bar As Integer
    bar = MyValue
End Sub

问题是:在对 的赋值中bar,使用的是属性还是参数?

标签: parameterspropertiesvb6

解决方案


一种检查方法是查看 IDE 认为将使用什么。

这是一个例子:

Property Get test() As Integer
    test = 1
End Property

Private Sub test2(test As Integer)
    Debug.Print test 'Place cursor here
End Sub

如果将光标放在test指示的行上并按Shift+ f2(或右键单击并选择定义),它会突出显示testin test As Integer(参数)。

作为仔细检查,如果您将参数重命名为其他名称并再次执行此操作,则它会突出显示名为test.

我认为这与编译器一致。


推荐阅读