|
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 blnSearchTemplateFor(strAr() As String, lngId As Long) As Boolean ' Procedure : blnSearchTemplateFor ' Description: Search a template for the use of an identifier. ' Locate any occurrence of the identifier at a line in the TEMPLATE. ' Copyright: Chris Greaves Inc. ' Inputs: 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 templates. ' It is easy enough to find the line which defines an identifier: ' You parse lines that start 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. ' Search the Template for the USE of the data identifier. blnSearchTemplateFor = False ' default result is "Not Found" Dim objModule As VBComponent ' fixed 2001/06/05 For Each objModule In ActiveDocument.VBProject.VBComponents If objModule.Type <> vbext_ct_Document Then If blnSearchModuleFor(objModule.Name, strAr, lngId) Then blnSearchTemplateFor = True Exit Function Else End If Else End If Next objModule 'Sub TESTblnSearchTemplateFor() 'Dim strAr(9, 1) As String 'strAr(0, 1) = "U" ' module 'strAr(1, 1) = "a" ' module 'strAr(2, 1) = "zboolUseIt" ' procedure 'strAr(3, 1) = "43" ' procedure 'strAr(4, 1) = "0" ' procedure 'MsgBox blnSearchTemplateFor(strAr, 1) ' should yield FALSE, provided the zboolit line above is at line 43 of this module 'strAr(2, 1) = "boolUseIt" ' procedure 'MsgBox blnSearchTemplateFor(strAr, 1) ' should yield TRUE, provided the BOOLIT line above is NOT at line 43 of this module '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 |