Question:  How does one do "reflection" in Visual Basic?

Answer:  Use COM "Type Library" information.

''(Assumption:  We're talking about VB4 thru VB6 -- not VB7 / VB.Net, which does things entirely differently.  See ReflectionInDotNet)''

----

From the Yahoo XP discussion group:

http://groups.yahoo.com/group/extremeprogramming/message/52628


'''''"A google groups search found a very consistent answer:  No, you can't do that in VB, [...]"'''''


Visual Basic 4..6 DLLs (and some EXEs) are COM servers. Embedded in 
the executable file is a COM "Type Library" containing definitions of 
all the public classes creatable from outside, along with their 
interfaces, including methods and parameters. (Every VB class is a 
COM interface.) Visual Studio comes with an "OLE Viewer" tool that 
can display type library contents in IDL (Interface Definition 
Language) syntax. IDL is C/C++ -like.

In theory, any Windows program can call standard COM functions to 
query the contents of a type library. But the functions are VB 
unfriendly, so you can't call them directly. There's 
an "unsupported" DLL in the VB6 installation that will give you 
access. Microsoft put out a help file that documents its use, with 
the usual disclaimers that they might change it on a whim. (.Net 
made the whole issue moot.)
-- JeffGrigg

"FILE: Tlbinf32.exe : Help Files for Tlbinf32.dll (Q224331)"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q224331

"Visual Basic: Inspect COM Components Using the TypeLib Information 
Object Library"
http://msdn.microsoft.com/msdnmag/issues/1200/TypeLib/TypeLib.asp
A pretty good article on browing Type Library information from VB6. 
(December 2000)


''I guess one could create reflection in VB, since the vbUnit guys did it. Hmmmm. Maybe I should look at the vbUnit code... -- Kay''

To find it in VbUnitThree...
Download http://www.maasscomputer.de/vbunit/vbUnit3.06.02.Basic.zip
Look at 'vbUnit3\vbUnitFramework\Reflector.cls'
-- JeffGrigg

----
CategoryReflection