Class module and "special attributes." (1 Viewer)

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:38
Joined
Feb 28, 2001
Messages
27,001
I have been playing around with a text parser that I created as a class object. I noticed that there are some attributes available so that if you have the object in the object browser, you can change the order in which they appear and can provide a simple text description. Something similar to

Code:
Public Property Get TokenSize() As Long
Attribute TokenSize.VB_Description = "Size of returned token in bytes"
Attribute TokenSize.VB_UserMemID= 4               'would appear 4th in the list of class object properties
...

However, even though the class itself seems to be working correctly, AC2010's VBA doesn't recognize the Attribute keyword. Has anyone played around with this sort of thing before? I got the reference to this ability from this article:

 

sonic8

AWF VIP
Local time
Today, 09:38
Joined
Oct 27, 2015
Messages
998
You need to export the class (including the attributes) to a file and then import it again. The attributes will become invisible but then they will have the intended effect.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:38
Joined
Feb 28, 2001
Messages
27,001
Not that simple. It says "syntax error" when I try to use Attribute. There is a "Let" and a "Get" for the particular property. I have tried putting the Attribute clause on the Let (which appears first) and on the Get but get the same result. When I follow the Help in that little pop-up, it is no help at all, but in the resulting help window I can ask for help on "Attribute." It says that it was in the wrong place. So I moved it to the class module's declaration area and I still get a Syntax error. I can't export the class with attributes because it won't compile.


VBAttribute.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:38
Joined
May 21, 2018
Messages
8,463
Do it the other way around. Get rid of that line. Export the class. Add the attributes in using a text editor. Import it. The lines will not show up.
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:38
Joined
Jan 23, 2006
Messages
15,364
Remove the terminating /bookmark to get to the post suggested by MajP
 

sonic8

AWF VIP
Local time
Today, 09:38
Joined
Oct 27, 2015
Messages
998
Correct. It will not compile, but that should not prevent you from exporting the module to a file.

Code:
Application.SaveAsText acModule, "ParserObj","c:\tmp\ParserObj.cls"
Application.LoadFromText acModule, "ParserObj","c:\tmp\ParserObj.cls"

It would work with Menu: "File" - "Export" as well.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:38
Joined
May 21, 2018
Messages
8,463
Remove the terminating /bookmark to get to the post suggested by MajP
Thanks I fixed it.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:38
Joined
Feb 28, 2001
Messages
27,001
OK, the result is that the attributes showed up in Object Browser when I export, edit externally, and import again. That is bizarre to my way of thinking though. It lets you have attributes but you can't declare them in the context of VBA and Access. You have to go outside to do it. I would NEVER have guessed that one. Thanks, MajP and Sonic8.

I'm now trying to eliminate things from the browser that I wanted kept not visible. I'm making some slow progress on that topic. I also have been putting together documentation so I could eventually upload this as a working class module for anyone who needs to do detailed text parsing of complex or general input streams.

For me it has been useful in analyzing my GEDCOM (Ancestry) files and for analysis of my novels so that I can do a cross-reference, frequency analysis, and a couple of other statistical things. It also worked in an Access analyzer tool I once built. And a variation of this was something I used to build a command-line calculator for a mainframe that didn't have such a utility. Worked really great for the parsing phase.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 19:38
Joined
Jan 20, 2009
Messages
12,849
OK, the result is that the attributes showed up in Object Browser when I export, edit externally, and import again. That is bizarre to my way of thinking though. It lets you have attributes but you can't declare them in the context of VBA and Access. You have to go outside to do it. I would NEVER have guessed that one.

I only knew about it through a discussion on here many years ago where the technique was used to set a Property as the default on a custom class and support a For Each iteration. I remember commenting how bewildering that would be for someone who didn't know about how it can be done.
 

Users who are viewing this thread

Top Bottom