Reputation: 1875
Hi So I am just Learning about VB's take on OOP. When testing how Let
,Get
methods work I created this dummy class Class1
, apprarently it cannot be compiled becasue "Ambigious name detected: ~" with this error VBE highlights line 2 of the class(one declaring test_property as Integer).
I don't understand what is a ambigious about it?
FYI I experiemented by trying to declare that proterty with Dim
& Public
none of those methods change anything.
See class Class1
bellow:
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
I am calling it using following test Sub:
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
Upvotes: 1
Views: 68
Reputation: 1106
You have a duplicate declaration of your Private property variable and your let and get public procedure properties. You should name your variable
Private itesting_property As Integer
You also have your Let before your Get. You should assign a value before you write it. Also, your Get() should not accept a variable and be dimmed as an integer, and your Let() should accept a variable as an integer and not be dimmed.
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
Upvotes: 3