VBA Introspection, partial success using tblinf32, but...

S

Steve Jorgensen

There are a large number of things I would like to do with code
introspection in VBA (MS Access), but the only ways I can find to do any
kind of introspection of a VBA project are using TLI (tlbinf32.dll), and
the only info I can get that way is about a class that I already have an
instance of.

So far, I cannot get any information about even a class module unless I
have other code that can generate an instance of it to pass to the TLI
functions, and I can't get info about non-class modules at all. What I can
do already is enough to write a VBA Unit tester, but it's not enough to do
some of the other things I'm itching to do.

Does anyone know how to take this to the next level?

Thanks,

- Steve J.
 
K

Klaus H. Probst

Well, you can do the same things if you work against a type library (or a
TLB embedded in an executable), but unless you figure out how VBA stores
that kind of metadata you won't get far.


--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/


Please post/reply to the newsgroup(s)
 
S

Steve Jorgensen

Well, you can do the same things if you work against a type library (or a
TLB embedded in an executable), but unless you figure out how VBA stores
that kind of metadata you won't get far.

Thanks for the rapid reply.

Yes, I figured out that I would need some way to access that metadata, and
since TLI requires a TBL, and VBA provides no direct access, I'll need some
way to dig it out. Of course, I have no idea how one would dig it out.

I had read (rightly or wrongly) that the VBIDE itself makes use of
tlbinf32.dll to provide the autosense help, and it clearly knows about all
the modules in a VBA project, so I was hopeful there's a way I can get at
the same info. I can't find any promising hooks anywhere in the VBIDE
library, though.
 
K

Klaus H. Probst

Yes, I figured out that I would need some way to access that metadata, and
since TLI requires a TBL, and VBA provides no direct access, I'll need
some
way to dig it out. Of course, I have no idea how one would dig it out.

Neither do I, honestly =)
I had read (rightly or wrongly) that the VBIDE itself makes use of
tlbinf32.dll to provide the autosense help, and it clearly knows about all
the modules in a VBA project, so I was hopeful there's a way I can get at
the same info. I can't find any promising hooks anywhere in the VBIDE
library, though.

VB uses the same type of *technology*, and TLBInf was written by the same
person who invented IntelliSense. But obviously as you're working within a
project the logic adds classes and modules dynamically to the intellisense
system instead of reading them from a binary. I can't see how you could hook
into this though.

Perhaps you could define all your interfaces in a typelib, add a reference
to it and then implement the interfaces in your VBA code. I don't even
recall if VBA supports the Implements keyword though, and of course this may
not be an option, especially if you're doing something that's generic, as
opposed to have it work just with your code.

Maybe the VBA SDK has some sort of hook or tool to facilitate this type of
thing, but then that's not cheap to say the least and I doubt you'll be able
to code a quick and dirty solution that way.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/


Please post/reply to the newsgroup(s)
 
D

Dave

Hi,
if I've understood you correctly ??? :)

add this reference ...
"Microsoft Visual Basic for Applications Extensibility 5.3"

Obviously the 'CodeModule' class and the related 'vbext_ComponentType' enum
would be of most interest to you.

hth,
Dave
 
S

Steve Jorgensen

Thanks for trying, but that does not do what I want.

That gets me a way to read thw text of a module, but what I want to do is
get what VBA knows about what that means without having to reinvent the
entire VBA parser. For instance, if the code has Dim x as clsFoo, VBA
knows whether clsFoo is a Dim statement vs being part of a quoted string vs
being part of a comment. It also knows whether clsFoo refers to a class in
the same project or one imported from another reference, and it knows what
public properties and methods are exposed by clsFoo.

If I were try to write code to do the same thing, it would be very complex
(handle continued lines, colon-delimited statements, precompiler
statements, etc.), and then it would still be likely to have missed some
particular and would need to be modified for each new version of VBA to
understand any new supported syntax. I was hoping for a way to get VBA to
tell me what it obviousy does know (as exemplified by auto-sense) about
what the code means.
 
A

Alexander Kienzle

Steve Jorgensen said:
There are a large number of things I would like to do with code
introspection in VBA (MS Access), but the only ways I can find to do any
kind of introspection of a VBA project are using TLI (tlbinf32.dll), and
the only info I can get that way is about a class that I already have an
instance of.

So far, I cannot get any information about even a class module unless I
have other code that can generate an instance of it to pass to the TLI
functions, and I can't get info about non-class modules at all. What I can
do already is enough to write a VBA Unit tester, but it's not enough to do
some of the other things I'm itching to do.

Does anyone know how to take this to the next level?

Thanks,

- Steve J.

To get information about VBA using TLBINF32.dll without creating an object
use:

Set TLibInfo = TLI.TypeLibInfoFromFile("C:\Windows\System32\msvbvm60.dll")

I tried that and found all (?) VB functions but I could only find 2 classes
(Collection and ErrObject) but maybe the other classes, like DataObject,
EventInfo,...
are somewhere burried down there. Open the locals window in the IDE when
your
typelibinfo object has been set and 'introspect'...

Hope this helps

Alexander Kienzle
 
S

Steve Jorgensen

To get information about VBA using TLBINF32.dll without creating an object
use:

Set TLibInfo = TLI.TypeLibInfoFromFile("C:\Windows\System32\msvbvm60.dll")

I tried that and found all (?) VB functions but I could only find 2 classes
(Collection and ErrObject) but maybe the other classes, like DataObject,
EventInfo,...
are somewhere burried down there. Open the locals window in the IDE when
your
typelibinfo object has been set and 'introspect'...

Hope this helps

Alexander Kienzle

Well, here are the problems with that, and a better explanation of what I'm
hoping to achieve than what's in my previous reply to Dave. I'd like to be
able to loop through all the modules (class or standard) in a project
(VBE(VBIDE) can do that part), and get TypeLib info about all the exposed
public interfaces of each, then locate the text of definitions of each of
the exposed members. I don't need any private member info (for the current
project ideas) except when those are the implementations of a publicly
exposed interface member or event.

What I -can- do so far is get info about just the default interface of a
class if I already have generated an instance of that class in code from
elsewhere, but this is not enough for what I'm hoping to do.

Thanks,

- Steve J.
 
S

Steve Jorgensen

Thanks,

Yes, I could (and possilby will) potentially do what I want using that
approach, but I was hoping not to. The problem is that it involves
duplicating in our own code much of what VBA/VBE already does, and hoping
we get it right, and it doesn't change in the next version in a way that
breaks our code. For instance, I notice that code doesn't appear to
account for the fact that VBA considers a line following a comment line
that ends with " _" to still be part of the comment. Sure, no one in their
right mind would use that form of commenting in their code, but this is at
least one example of how difficult it is to exactly duplicate one parsing
system using another and why it would be preferable to get the original
system to tell us what it's thinking.
 
P

Peter Huang [MSFT]

Hi Steve,

I am researching the issue, based on my research, the way is a possible
solution.
If I have new information, I will update you with new information.
Cheers!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
S

Steve Jorgensen

Since all I've done is complain about the responses I've received so far, I
wanted to be sure to thank those who are trying to help me. The responses
have been useful, I'm just still looking for the perfectionist answer if I
can get one.

I'll continue to be grateful for any additional help in this area.

Thanks,

- Steve J.
 
P

Peter Huang [MSFT]

Hi Steve,

If you integrate VBA (by paying the license fees) then you potentially have
access to this information. Otherwise, you do not.
They can look at the eval version of the 6.3 VBA SDK:
http://msdn.microsoft.com/vba/eval/evalcd.asp
for starters.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
X-Tomcat-ID: 82776990
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Thu, 02 Oct 2003 03:22:57 GMT
Subject: Re: VBA Introspection, partial success using tblinf32, but...
X-Tomcat-NG: microsoft.public.office.developer.vba
Message-ID: <[email protected]>
Newsgroups: microsoft.public.office.developer.vba
Lines: 71
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.vba:17111
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Steve,

I am researching the issue, based on my research, the way is a possible
solution.
If I have new information, I will update you with new information.
Cheers!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: Steve Jorgensen <[email protected]>
Newsgroups: microsoft.public.office.developer.vba
Subject: Re: VBA Introspection, partial success using tblinf32, but...
Message-ID: <[email protected]>
References: <[email protected]>
X-Newsreader: Forte Free Agent 1.92/32.572
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 30
NNTP-Posting-Host: 12.225.222.252
X-Complaints-To: (e-mail address removed)
X-Trace: rwcrnsc51.ops.asp.att.net 1064985185 12.225.222.252 (Wed, 01 Oct 2003 05:13:05 GMT)
NNTP-Posting-Date: Wed, 01 Oct 2003 05:13:05 GMT
Organization: Comcast Online
Date: Wed, 01 Oct 2003 05:13:06 GMT
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
n
e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthli
n
k.net!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_
f
eed4!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.vba:17101
X-Tomcat-NG: microsoft.public.office.developer.vba

Thanks,

Yes, I could (and possilby will) potentially do what I want using that
approach, but I was hoping not to. The problem is that it involves
duplicating in our own code much of what VBA/VBE already does, and hoping
we get it right, and it doesn't change in the next version in a way that
breaks our code. For instance, I notice that code doesn't appear to
account for the fact that VBA considers a line following a comment line
that ends with " _" to still be part of the comment. Sure, no one in their
right mind would use that form of commenting in their code, but this is at
least one example of how difficult it is to exactly duplicate one parsing
system using another and why it would be preferable to get the original
system to tell us what it's thinking.

rights.
 
S

Steve Jorgensen

Thank you. That information is -precisely- what I needed to know in this
arena. :)

Hi Steve,

If you integrate VBA (by paying the license fees) then you potentially have
access to this information. Otherwise, you do not.
They can look at the eval version of the 6.3 VBA SDK:
http://msdn.microsoft.com/vba/eval/evalcd.asp
for starters.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
X-Tomcat-ID: 82776990
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Thu, 02 Oct 2003 03:22:57 GMT
Subject: Re: VBA Introspection, partial success using tblinf32, but...
X-Tomcat-NG: microsoft.public.office.developer.vba
Message-ID: <[email protected]>
Newsgroups: microsoft.public.office.developer.vba
Lines: 71
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.vba:17111
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Steve,

I am researching the issue, based on my research, the way is a possible
solution.
If I have new information, I will update you with new information.
Cheers!

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: Steve Jorgensen <[email protected]>
Newsgroups: microsoft.public.office.developer.vba
Subject: Re: VBA Introspection, partial success using tblinf32, but...
Message-ID: <[email protected]>
References: <[email protected]>
X-Newsreader: Forte Free Agent 1.92/32.572
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 30
NNTP-Posting-Host: 12.225.222.252
X-Complaints-To: (e-mail address removed)
X-Trace: rwcrnsc51.ops.asp.att.net 1064985185 12.225.222.252 (Wed, 01 Oct 2003 05:13:05 GMT)
NNTP-Posting-Date: Wed, 01 Oct 2003 05:13:05 GMT
Organization: Comcast Online
Date: Wed, 01 Oct 2003 05:13:06 GMT
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli
n
e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthli
n
k.net!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_
f
eed4!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.office.developer.vba:17101
X-Tomcat-NG: microsoft.public.office.developer.vba

Thanks,

Yes, I could (and possilby will) potentially do what I want using that
approach, but I was hoping not to. The problem is that it involves
duplicating in our own code much of what VBA/VBE already does, and hoping
we get it right, and it doesn't change in the next version in a way that
breaks our code. For instance, I notice that code doesn't appear to
account for the fact that VBA considers a line following a comment line
that ends with " _" to still be part of the comment. Sure, no one in their
right mind would use that form of commenting in their code, but this is at
least one example of how difficult it is to exactly duplicate one parsing
system using another and why it would be preferable to get the original
system to tell us what it's thinking.

Hi Steve,

You may have a look at sample below.

http://www.appspro.com/
VBA Code Documentor

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top