vba - VBE 看到模棱两可的名称

标签 vba oop excel

嗨所以我只是在学习 VB 对 OOP 的看法。测试时如何 Let , Get方法工作我创建了这个虚拟类Class1 ,显然它不能被编译,因为“检测到歧义的名称:~”这个错误 VBE 突出显示类的第 2 行(一个声明 test_property 为整数)。

我不明白什么是模棱两可的?

仅供引用,我尝试用 Dim 声明该属性& Public这些方法都没有改变任何东西。

见类(class)Class1波纹管:

Option Explicit
Private testing_property As Integer

Public Property Let testing_property(new_value As Integer)
    MsgBox "Let Box"
    Let testing = new_value
End Property

Public Property Get testing_property(new_value As Integer) As Integer
    MsgBox "Get Box"
End Property

我使用以下测试子调用它:
Sub Test()
    Dim test_Class As Class1
    Set test_Class = New Class1
    With test_Class
        .testing_property = "1"
        Debug.Print .testing_property
    End With
End Sub

最佳答案

您的 Private 属性变量和您的 let 和 get 公共(public)过程属性的重复声明。你应该命名你的变量

Private itesting_property As Integer

你也有你的让在你的得到之前。您应该在编写之前分配一个值。此外,您的 Get() 不应接受变量并将其调暗为整数,而您的 Let() 应将变量视为整数且不应调暗。
Public Property Get testing_property() As Integer
    MsgBox "Get Box"
    testing_property = itesting_property
End Property
Public Property Let testing_property(new_value As Integer)
    MsgBox "Let Box"
    itesting_property = new_value
End Property

关于vba - VBE 看到模棱两可的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29129569/

相关文章:

excel - VBA 宏 : Using variables with type modifier

vba - 在 VBA 中对多个键进行排序;运行时错误 450 : Wrong number of arguments or invalid property assignment

excel - 将来自多个工作表的数据与可变工作表名称组合在一起

oop - 在 UML 类图中,组合可以是双向的吗?

excel - 如果列中的单元格有数据,则复制并粘贴到同一行中的不同单元格

vba - Excel VBA : Date Comparison

javascript - 单独适用于页面上多个元素的方法

python 继承: choose parent class using argument

vba - 在 VBA 中,创建对象与不创建对象时的语法是否不同?

excel - 合并列 VBA 时不会粘贴前导零