VBE 看到 Ambigious Name
VBE sees Ambigious Name
您好,我刚刚了解 VB 对 OOP 的看法。在测试 Let
、Get
方法如何工作时,我创建了这个虚拟 class Class1
,显然它无法编译,因为 "Ambigious name detected: ~" 出现此错误 VB E 突出显示 class 的第 2 行(其中一个声明 test_property 为 Integer)。
不明白什么叫暧昧?
仅供参考,我尝试通过 Dim
和 Public
none 声明该属性来改变任何东西。
请参阅下面的 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。您应该在编写之前分配一个值。此外,您的 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
您好,我刚刚了解 VB 对 OOP 的看法。在测试 Let
、Get
方法如何工作时,我创建了这个虚拟 class Class1
,显然它无法编译,因为 "Ambigious name detected: ~" 出现此错误 VB E 突出显示 class 的第 2 行(其中一个声明 test_property 为 Integer)。
不明白什么叫暧昧?
仅供参考,我尝试通过 Dim
和 Public
none 声明该属性来改变任何东西。
请参阅下面的 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。您应该在编写之前分配一个值。此外,您的 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