Visual Basic (VB6 and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

Visual Basic Library

This page was last updated on Saturday, November 24, 2001

Public Function blnSearchModuleFor(strModule As String, strAr() As String, lngId As Long) As Boolean ' Procedure : blnSearchModuleFor ' Description: Search a module for the use of an identifier. ' Locate any occurrence of the identifier at a line in the module OTHER THAN the definition line ' Copyright: Chris Greaves Inc. ' Inputs: STRING module name, STRING symbol table, LONG index to line-of-declaration. ' Returns: TRUE if a use of the identifier is found. ' Assumes: None. ' Side Effects: None. ' Tested: By the calls shown below. ' A handy function if ever you decide to create a cross-reference table for modules. ' It is easy enough to find the line which defines an identifier: ' You parse lines that start PUBLIC or PRIVATE or DIM and so on. ' In order to see if the identifier is used, you need to find a place OTHER THAN ITS DEFINITION ' where the identifer is referenced. ' The symbol table is a 4-column table, defined as: ' dim strTable(3,100) (if you have 100 identifiers ' The column(2,) contains the identifier ' The column (3,) holds a string representation of the line number at which the identifier is declared. ' Please see the test module for a sample setup of this table. blnSearchModuleFor = False ' default result is "Not Found" Dim strId As String strId = UCase(strAr(2, lngId)) ' case-insensitive comparisons Dim objModule As VBComponent For Each objModule In ActiveDocument.VBProject.VBComponents If objModule.Name = strModule Then ' we are in the module-to-be-searched. ' Examine each line of the module until such time as a sutably "hit" is found. Dim lngLines As Long lngLines = objModule.CodeModule.CountOfLines Dim lngLine As Long For lngLine = 1 To lngLines If InStr(1, UCase(objModule.CodeModule.Lines(lngLine, 1)), strId) > 0 Then ' We have found an instance the identifier If lngLine = strAr(3, lngId) Then ' it is the definition, so continue the search Else ' We have found a non-definition instance of the identifer in this module. blnSearchModuleFor = True Exit Function End If Else End If Next lngLine Else End If Next objModule 'Sub TESTblnSearchModuleFor() 'Dim strAr() As String 'ReDim strAr(3, 2) 'strAr(2, 1) = "neverfound" 'strAr(3, 1) = "207" 'strAr(2, 2) = "oLstTemplate" 'strAr(3, 2) = "207" 'MsgBox blnSearchModuleFor("U", strAr, 2) ' TRUE 'MsgBox blnSearchModuleFor("U", strAr, 1) ' FALSE 'End Sub End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Monday, November 19, 2001

 

 

Hosted by www.Geocities.ws

1