2

I have created a custom class in VBA, and it uses several private properties that help the class fulfill its purpose internally. Most of these properties I will (likely) never need to see in any inspector. However, when I inspect an instance of my class in the locals or watch windows, all its properties appear, even these unnecessary helper properties. They tend to visually bury the useful properties that I want to inspect.

Is there a way to mark certain properties in my custom class so that they don't appear when inspecting an instance of the class in the locals or watch windows? Is there a setting in the editor that would allow me to hide these private properties? Are there any tricks or hacks that can accomplish at least something similar?

JDCAce
  • 159
  • 12
  • No that I know of. The VBE is showing its age - it dates back to Office 95(!) – Gustav Oct 14 '21 at 06:27
  • 1
    Yes. Encapsulate your properties in a private user defined type. For example I use udts of Properties and State, declared as variables p and s. This idea is derived from a Rubber duck blog which used a udt of TClassname and a variable of 'this' to emulate the 'this' qualifier found in languages such as C#. Think of 'this' as an internal 'Me' – freeflow Oct 14 '21 at 07:48
  • @freeflow I am not sure he is asking about private variables (in which case your advice would definitely help). It looks like he is asking about private ```Property Get``` procedures in which case your advice won't help. Maybe the OP can clarify – Cristian Buse Oct 14 '21 at 08:10
  • @CristianBuse. The use of private UDTs to collate backing variables is easily adapted to organising private variable by importance. Put the important ones in a UDT attached to variable s and umimportant oines in a UDT attached to variable su. Or any variation thereof the OP wishes to use. – freeflow Oct 14 '21 at 08:19
  • @freeflow I am not arguing with the usefulness of that. I already mentioned in my previous comment that it would be definitely useful. What I was saying is that I am not sure this is what the OP is asking. He might be asking about private ```Property Get``` procedures and the UDTs would not help with that in terms of what the Local/Watch window is showing. Again, your advice is useful but not sure it's addressing the question because the question is not fully explicit. – Cristian Buse Oct 14 '21 at 08:25
  • @CristianBuse I get your point now. I see Private Property Get etc as very bad practise so it didn't even register on my consciousness. I guess the OP needs to consider if his private property get are really part of his class or if they should be encapsulated in another class. – freeflow Oct 14 '21 at 08:28
  • @freeflow I agree with you. If it's private it should be a Sub/Function. I've never seen an actual case where a private Property Get is used. I myself don't think I ever used one. Maybe OP can clarify – Cristian Buse Oct 14 '21 at 08:32
  • 2
    If it turns out the OP indeed meant private variables, rather than private properties, this would be a duplicate of: [How to prevent showing backing private fields of class properties in the Locals window?](https://stackoverflow.com/q/45569332/8967612) – 41686d6564 stands w. Palestine Oct 14 '21 at 08:51
  • 1
    Thanks, everyone, for the discussion! I did indeed mean "variable/field" rather than "property". Sorry for the confusion. Hiding them inside a private custom type like @freeflow and the blog suggested is brilliant. It doesn't completely eliminate them from the windows, but it definitely reduces clutter, which was my goal. I'm not sure what to do with this question from here. Someone should probably mark this as a duplicate as 41686d6564 mentioned. – JDCAce Oct 15 '21 at 04:32

0 Answers0