Developer Documentation Library > Scripting > mrScriptBasic overview > mrScriptBasic examples > Example 10: Enumerating the table and interview object model type library information
 
Example 10: Enumerating the table and interview object model type library information
The Script Engine allows you to access the type library information for available UNICOM Intelligence objects. This example provides a simple method for using a standard Microsoft object to create a text file and an UNICOM Intelligence Data Model object in order to retrieve a type information list for the UNICOM Intelligence Reporter Tom Document Class and the UNICOM Intelligence IOM RunningInterviews Class.
The code writes the name and parameters for each function and property to a text file.
Code
This example is included with the UNICOM Intelligence Developer Documentation Library as the sample script EnumerateTypeLibraryInfo.mrs. See Sample mrScriptBasic files for more information.
' This script demonstrates how the mrScriptBasic type system can be used
' to enumerate the properties and methods of a Type Library
Dim Engine, Type, Libraries[], Parameter, fso, txtfile, LibraryName

Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("C:\Output\LibTypeInfo.txt", True)

Set Engine = CreateObject("mrScript.ScriptEngine")

' UNICOM Intelligence TOM Library
' The TypeLib can be retrived from HKCR\CLSID\{04E94295-A0F4-4011-9AE1-A1EC664375C3}\TypeLib
Const TOM_TYPELIB_GUID = "{8ddc01c5-f4ce-4fac-ba84-49e804806ec8}"
Engine.Types.AddRegTypeLib(TOM_TYPELIB_GUID, 1, 0)
Libraries[0] = Engine.Types.GetLibraryName(TOM_TYPELIB_GUID, 1, 0)

' UNICOM Intelligence IOM Library
' The TypeLib can be retrived from HKCR\CLSID\{16268F26-8522-49E4-A382-56E49E73FB63}\TypeLib
Const IOM_TYPELIB_GUID = "{CD3747E5-83EC-4926-B044-9AFC574C572F}"
Engine.Types.AddRegTypeLib(IOM_TYPELIB_GUID, 1, 0)
Libraries[1] = Engine.Types.GetLibraryName(IOM_TYPELIB_GUID, 1, 0)

For Each Type in Engine.Types
' Skip any libraries not explicitly loaded
If Libraries.FindItem(Type.Library) <> NULL And Not Type.IsHidden Then

' Check to see if this is a new library
If Type.Library <> LibraryName Then
If LibraryName <> NULL Then txtfile.WriteLine()
LibraryName = Type.Library
txtfile.WriteLine("Library " + LibraryName)
End If

' Enumerate the type
If Type.IsEnum Then
EnumerateEnumTypeMembers(Type, txtfile)
Else
If Type.IsInterface Then
txtfile.WriteLine(" Interface " + Type.Class)
Else
txtfile.WriteLine(" Class " + Type.Class)
End If
EnumerateMembers(Type, txtfile)
EnumerateMethods(Type, txtfile)
End If
End If
Next
txtfile.Close()

' Helper Methods for outputing Type library information
Sub EnumerateEnumTypeMembers (Type, txtfile)

' Output the Enum memebers
Dim MemeberInfo, Memeber, Count, Value
Count = Type.Members.Count
If Count <= 0 Then
Exit Sub
End If

txtfile.WriteLine(" Enum " + Type.Class)
For Each Memeber in Type.Members
MemeberInfo = " Const "
MemeberInfo = MemeberInfo + Memeber.Name
MemeberInfo = MemeberInfo + " = "
MemeberInfo = MemeberInfo + CText(Memeber.GetValue(Memeber))
txtfile.WriteLine(MemeberInfo)
Next

End Sub

Sub EnumerateMembers (Type, txtfile)

' Output the Type's properties
Dim MemeberInfo, Memeber, Count, Value

Count = Type.Members.Count
If Count <= 0 Then
Exit Sub
End If

For Each Memeber in Type.Members
If Memeber.IsHidden = False Then
MemeberInfo = " "
MemeberInfo = MemeberInfo + Memeber.Name
MemeberInfo = MemeberInfo + " As "
MemeberInfo = MemeberInfo + CText(Memeber.Type.Class)
If Memeber.CanRead And Memeber.CanWrite Then
MemeberInfo = MemeberInfo + " (Read/Write) "
ElseIf Memeber.CanRead Then
MemeberInfo = MemeberInfo + " (Read-only) "
Else
MemeberInfo = MemeberInfo + " (Write-only) "
End If
txtfile.WriteLine(MemeberInfo)
End If
Next

End Sub

Sub EnumerateMethods (Type, txtfile)

' Output the Type's methods
Dim MethodInfo, Method, Count, Index, Parameter, ParameterCount
Dim ParameterInfo

Count = Type.Methods.Count
If Count <= 0 Then
Exit Sub
End If

For Each Method in Type.Methods
If Method.HasReturnType Then
MethodInfo = " Function "
Else
MethodInfo = " Sub "
End If
MethodInfo = MethodInfo + Method.Name
MethodInfo = MethodInfo + "("
ParameterCount = Method.Parameters.Count
ParameterInfo = ""
Index = 0

' Output the Method's Parameters
For Each Parameter in Method.Parameters
If Parameter.IsOptional Then ParameterInfo = ParameterInfo + "["
ParameterInfo = ParameterInfo + Parameter.Name
ParameterInfo = ParameterInfo + " As "
ParameterInfo = ParameterInfo + CText(Parameter.Type.Class)
If Parameter.IsParamArray Then ParameterInfo = ParameterInfo + ", ..."
If Parameter.IsOptional Then ParameterInfo = ParameterInfo + "]"

If Index < ParameterCount-1 Then
ParameterInfo = ParameterInfo + ", "
End if
Index = Index + 1
Next

ParameterInfo = ParameterInfo + ")"
MethodInfo = MethodInfo + ParameterInfo
If Method.HasReturnType Then
MethodInfo = MethodInfo + " As "
MethodInfo = MethodInfo + Method.ReturnType.Class
End If

txtfile.WriteLine(MethodInfo)
Next

End Sub
Result
The resulting text output resembles the following:
Class Document
Description AS Text (Read/write)
Language AS Text (Read/write)
Context AS Text (Read/write)
LabelType AS Text (Read/write)
Tables AS Tables (Read-only)
DataSet AS DataSet (Read-only)
Default AS TableDefaults (Read-only)
Global AS TableGlobals (Read-only)
Axes AS Axes (Read-only)
Filters AS Filters (Read-only)
Statistics AS Statistics (Read-only)
LogFilePath AS Text (Read/write)
KeepLogFiles AS Boolean (Read/write)
RawStatisticsData AS Text (Read/write)
OutputLocaleId AS Long (Read/Write)
Exports AS Exports (Read-only)
ToMversion AS Text (Read-only)
CreatedByversion AS Text (Read-only)
LastUpdatedByversion AS Text (Read-only)
ImageLocation AS Text (Read/write)
LicensedFeatures AS Long (Read-only)
RawStatisticsDataEnabled AS Boolean (Read/write)
GroupedTables AS TableListNode (Read-only)
Properties AS IProperties (Read-only)
Parent AS Object (Read-only)
SaveProfileResults AS Boolean (Read/write)
ProfileDefault AS TableDefaults (Read-only)
PopulateStatus AS Text (Read-only)
PopulateProgress AS Long (Read-only)
IsPopulating AS Boolean (Read-only)
Coding AS Coding (Read-only)
Openoption AS Qpenoptions (Read/write)
ProfileSpecial—lements AS Boolean (Read/Write)
Sub Open(Source AS None, IncludeResults AS Boolean)
Sub Save(Destination AS None, IncludeResults AS Boolean)
Function Populate(Ttables AS None) AS Boolean
Sub ClearQ)
Function GenerateScript(Tables AS None, Type AS ScriptType, Op
See also
mrScriptBasic examples