Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuing with extensibility

Status
Not open for further replies.

easycode

Programmer
Jan 28, 2005
195
US
Hi all

I've been advised about adding header comments to a software, i am using a reference to the Microsoft VB Application extensibility, it works but i need to modify a little bit. I need to know the number of procedures in the software, comprised forms, modules, reports anything that can have code or can be coded.
i.e.
a form can have 2 functions and 2 private subs.
another form can have 3 private subs.
a report can have 2 Private Subs
a module can have a function and 2 private Subs.

in the last example i have 12 procedures in the whole system
which is in 2 forms, a module and a report.
I need to get that number 12 by coding using a property. I was using the next code:

Dim oVBE As VBIDE.VBE
Dim oCM As CodeModule
Dim numprog As Integer

Set oVBE = Application.VBE
Set oCM = VBE.ActiveVBProject.VBComponents(1).CodeModule
numprog = oCM.CodePane.Collection.Count

numprog was the number of procedures, and it was working fine, but now is not. Could anyone advise. Thank you
 
microsoftaccess2000,
No idea why it stopped working but looking at it everytime you call [tt]CodePane[/tt] the VBE will open a pane if it dosen't already exist which can slow the routine down (although with 12 procedures probably not very much).

Here is a sample that does the same type of thing, if I run this on my current project (81 code modules, 441 procedures) it takes about 1.5 seconds and allows module/procedure names and locations to be reported if needed (I use this as part of a routine to document databases before delivery to clients).

Code:
Function CountProcedures() As Long
Dim objProj As VBProject
Dim objComponent As VBComponent
Dim numprog As Integer, intLine As Integer
Dim strProcedureName As String

Set objProj = Application.VBE.ActiveVBProject
For Each objComponent In objProj.VBComponents
  For intLine = 1 To objComponent.CodeModule.CountOfLines
    If strProcedureName <> objComponent.CodeModule.ProcOfLine(intLine, vbext_pk_Proc) Then
      numprog = numprog + 1
      strProcedureName = objComponent.CodeModule.ProcOfLine(intLine, vbext_pk_Proc)
    End If
  Next intLine
Next objComponent
Set objComponent = Nothing
Set objProj = Nothing
CountProcedures = numprog
End Function

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top