VB Reference Guide
This document provides some more detailed information about the objects and links that are stored in the Analysis Service. Other technical information may also be available.
Object Types
Objects detected by the analyzer are summarized in the following table:
Class Module | |
Constant | |
Control | |
Designer | |
Event | |
External Function | |
External Sub | |
Form | |
Function | |
MDI Form | |
Module | |
Control Project | |
EXE Project | |
Group Project | |
OLE DLL Project | |
OLE Exe Project | |
Get Property | |
Let Property | |
Page Property | |
Set property | |
Sub | |
User Control | |
User Document | |
Variable | |
Com CoCLass | |
| |
| |
|
Link Types
The following table describes references that are detected by the analyzer and the context in which corresponding links are traced and stored in the Analysis Service:
Link Type | When is this type of link created? |
Call | - When calling a VB or a COM function (sub, function, property get, let set, com method, com prop put, prop putref, prop get) except system functions (functions from VB, VBA or VBRUN DLLs) - When calling a VB or a COM event - When the return type of a function is not a standard one Here is a sample that shows one of these links. Private Sub MySub(i As Integer) 'Do Whatever End Sub Private Sub Command1_Click() Dim j As Integer MySub (j)End Sub This will result in the following view:
|
Raise | - When raising an event In the following sample, we have a class (Class1) that defines an event (Gong) and a method (MyMethod). When MyMethod is called, we raise an event. Event Gong()Public Sub MyMethod()RaiseEvent GongEnd Sub This will result in the following view (includes only event relevant links):
|
Use | There is also a Form (Form1) that has the button (Command1). Here's the code of this Form: Private WithEvents mHandler As Class1Private Sub Command1_Click() Set mHandler = New Class1 mHandler.MyMethodEnd SubPrivate Sub mHandler_Gong()MsgBox "Gong !"End Sub - When declaring a user data-type, link with the non standard members of this user data-type - When referencing a non standard type member of a user data-type variable
- When accessing a variable
|
Rely On | - When declaring a variable of a non standard type
- When declaring a function return value of a non standard type |
Inherit | - When a user control inherits from a non standard type In this sample, the user control "UserControl1" is used in the form "Form1"
- When implementing an event using WithEvents statement
|
VB Standard APIs
Standard VB APIs (VBA, VB, VBRUN) delivered with the various versions of Visual Basic are too big to be analyzed on each analysis. More over, you do not need to install Visual Basic in order to launch VB Analyzer. Consequently these APIs have been pre-parsed and the underlying classes are packaged with the analyzer. The VB APIs are then loaded depending on the version and redeployed on demand during the analysis.
This has the following consequences:
- VB standard objects are not stored in the Analysis Service.
- Even if references to standard VB objects are resolved by the analyzer, corresponding links are not traced and consequently not stored.
- For the CreateObject method and CreateInstance method, the analyzer will create a link between the caller of these methods and the COM CoClass of the first parameter of these methods.
Resolution of C/S links and Late Binding through inference engine
It is possible to configure the analyzer to identify links to COM components for example if you have developed your own function such as MyCreateObject( "A.B") which in turn calls CreateObject. However, the analyzer needs to be configured. This can be done by using the Parametrization feature via a custom VB Environment Profile.
How does this work?
The inference engine handles all the variables or type members with the following types:
- Object
- Variant
- String
- or type calling a VB object (for example: Dim var as New Class1)
For Client/Server Links
All character stings that are likely to be sent to the "grep" are intercepted in function calls, affectations and control properties. In all other places, no C/S link is possible.
In addition, even though there is var = "authors" in the code does not automatically mean that there is a link to the AUTHORS table. In order for this to be true, there must be at least one function call that "parametrizes" the variable directly or indirectly.
The instruction blocks If...Then...Else, Do (While|Until) ... Loop, For ... Next, For Each ... Next, While .. .Wend, Select Case ... End Select are included in the inference engine which enables various possibilities for the same variable.
The following example displays what is now found with the new improvements to VB Analyzer:
dim var1 as Stringdim var2 as Stringdim var3 as StringPrivate Sub Form_Load(Optional Param1 As Variant = "authors")'If ( f(2) = 1 ) Then var1 = "authors" else var1 = "titles"var2 = var1f( var2 ) Links with tables AUTHORS and TITLES with a bookmark locatedon the if...then...else instruction. If f had not been called, no link would have been identified with the tables AUTHORS and TITLES.var3 = CStr ( Param1 )g( Param1 ) Link with the table "AUTHORS" for the declaration of the parameter Param1if ( var1 = "titlesauthor" ) Then g There will be no link with thetable TITLESAUTHOR because this is a test and not an affectation.if ( g("titlesauthor") = TRUE ) Then ... A link with TITLESAUTHOR will be established because a method is being executed which couldinclude a C/S call.if ( g(var3) = TRUE ) Then .. Link established with AUTHORS for thesame reason as the preceding instruction.End Sub
It is also possible to filter methods that do not include C/S calls. For example, including MsgBox var3, would enable you to filter the created C/S link with the table AUTHORS.
For Client/Client links
The following is handled:
Dim var as objectfunction f() as booleandim var1 as stringif ( test ) then var1 = "A.B"else var1 = "A.C"end ifset var = createobject(var1) ' Link with the coclasses B and Cvar.method1 ' Link with the methods method1 of B and Cend function
This applies to all methods (and not just to CreateObject or CreateInstance) described in the parameters table, or to a form that has the following code:
Option ExplicitDim udtCarre As clsDessinPrivate Sub cmdSurface_Click() Dim Surface As Long Set udtCarre = New clsCarre udtCarre.X = Val(txtX.Text) udtCarre.Y = Val(txtY.Text) Surface = udtCarre.Aire lblSurface.Caption = SurfaceEnd Sub
In this case, a link is traced between cmdSurface_Click and clsCarre and the inference engine allows the creation of a link to clsDessin_X ,clsDessin_Y and clsDessin_Aire from clsCarre.