Solved Property Declaration error - Why (1 Viewer)

ironfelix717

Registered User.
Local time
Today, 18:40
Joined
Sep 20, 2019
Messages
193
Unless I've lost my mind, the following property declarations are 100% VALID and the compiler is whining about the property declaration being inconsistent, duplicate, etc...

  1. The property is not duplicate, or has any variable of the same name
  2. The LET and GET statement are correctly formatted
  3. The prop variable is valid and exists
  4. The declaration is of the same type for both LET and GET.

Can someone put a set of eyes on this?
Code:
Property Let ParentTable(value As String)
'MANUALLY SET THE PARENT TABLE
'CLEAR PROPERTY BY SETTING IT = ""
vParentTable = value
End Property


Property Get ParentTable(Item As ItemTypes) As String
'RETRIEVES THE NAME OF THE PARENT TABLE FOR OPERATIONS, MATERIALS, OR TOOLING
If vParentTable <> "" Then ParentTable = vParentTable: Exit Property
If vType = 1 Then
    Select Case Item
        Case Operations: ParentTable = "LOC_Operations"

        Case materials: ParentTable = "LOC_OperationsMaterials"

        Case Tooling:   ParentTable = "LOC_OperationsTooling"
    End Select
Else
    Select Case Item
        Case Operations: ParentTable = "USR_Operations"

        Case materials: ParentTable = "USR_OperationsMaterials"

        Case Tooling: ParentTable = "USR_OperationsTooling"

    End Select
End If
End Property
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:40
Joined
May 21, 2018
Messages
8,605
any chance in your class variables you forgot the V in vParentTable? In that case you could have a property and a variable with the same. I tested that and I go an "ambigous name error" not a duplicate.
I would search through the whole project for ParentTable, you may have just left a public variable or method somewhere.

Can you post the whole class?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:40
Joined
May 21, 2018
Messages
8,605
Also "Item" should be fine as a variable, but I would do something else to be safe. Itm. It is not a keyword that the compiler would flag, but it is a reserved word
 

ironfelix717

Registered User.
Local time
Today, 18:40
Joined
Sep 20, 2019
Messages
193
Also "Item" should be fine as a variable, but I would do something else to be safe. Itm. It is not a keyword that the compiler would flag, but it is a reserved word
Replacing it seems to not have worked. I'm going to have to sift through this. This problem did not show up until i decided to put a LET declaration for this property. It was read-only until now.

Keywords are keywords because they're GOOD words. Its a shame MS locked down half the English dictionary.


I can't post the whole class without some additions to the code because it contains third party functions that are not included in the module.

I'm probably going to have to either sift through the code extensively. Or... ignore this petty issue and continue on my life by handling this LET declaration with a simple method - which is frankly not so elegant, but if it works, it works.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:40
Joined
May 21, 2018
Messages
8,605
The issue is the parameterized Get. If you remove it, it compiles. I am not sure if this can be done in VBA. I would simply replace the get with a function.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:40
Joined
May 21, 2018
Messages
8,605
Optional. List of variables representing arguments that are passed to the Property Get procedure when it is called. Multiple arguments are separated by commas. The name and data type of each argument in a Property Get procedure must be the same as the corresponding argument in a Property Let procedure (if one exists
 

ironfelix717

Registered User.
Local time
Today, 18:40
Joined
Sep 20, 2019
Messages
193
I already attempted to make the args the same type (as per MS docs) and it wouldn't compile. Now it does. Whatever.
Update: Incorrect above. It still will not compile if the argument is the same data type in both LET and GET. Not spending any more time on this petty issue.

I could replace it with a function, but its a primitive element to the class. From an abstract/interpretative sense, this appears much better to me as a property. I'm going to resort to making the LET property a function, as the GET will be accessed by the caller much more often and seems more 'natural' to me.

Thanks - this was quite dumb.

Regards
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:40
Joined
May 21, 2018
Messages
8,605
This may interest you it solved a huge problem for me.

Code:
Public Property Get Item(Optional Key As String) As Variant
  Item = Me.ItemDictionary.Item(Key)
End Property

Public Property Let Item(Optional Key As String, ByVal Value As Variant)
  If Value = 0 Then
     If Me.ItemDictionary.Exists(Key) Then Me.Remove (Key)
     Me.Length = Me.Length - 1
   Else
     If Me.ItemDictionary.Exists(Key) Then
       Me.ItemDictionary(Key) = Value
     Else
       Me.ItemDictionary.Add Key, Value
       Me.Length = Me.Length + 1
     End If
   End If
End Property

Usage
Code:
Public Sub test()
   Dim sp As New SP_SparseWordVector
  sp.Initialize
  sp.Item("A") = 1
  sp.Item("B") = 2
  Debug.Print sp.Item("A")
  'Debug.Print sp.Item_ByIndex(0)
  sp.Item("A") = 3
  Debug.Print sp.Item("A")
 End Sub

I cannot really wrap my head around how this works because in the LET notice the first parameter ("A") gets passed in like a regular parameter and the second parameter (1) is assigned by the equality
sp.Item("A") = 1

So now my custom Item property functions more like any other Item of a collection.
 

ironfelix717

Registered User.
Local time
Today, 18:40
Joined
Sep 20, 2019
Messages
193
This may interest you it solved a huge problem for me.
@MajP

My head is rusty. Haven't been writing VBA in a week so i'm foggy. But if I am able to wrap my head around this, i'll resume the discussion.

Thanks for contributing. Interesting.
 

Users who are viewing this thread

Top Bottom