ProcOfLine 属性返回一个只读字符串,该字符串包含标准模块或类模块中指定行所在过程的名称。
expression.ProcOfLine(Line, pprockind)
expression 必需。返回“应用于”列表中的一个对象的表达式。
Line 必需 Long 型。模块中的行号。
pprockind 必需 vbext_ProcKind 型。是包含 Line 参数指定行的过程的类型。该常量可以是下列值之一:
常量 |
说明 |
vbext_pk_Get |
Property Get 过程。 |
vbext_pk_Let |
Property Let 过程。 |
vbext_pk_Proc |
Sub 或 Function 过程。 |
vbext_pk_Set |
Property Set 过程。 |
ProcOfLine 属性仅在使用 Visual Basic 时才可用。
对于任何给定的行号,ProcOfLine 属性返回包含该行的过程的名称。因为过程定义之前的说明语句和编译常量被认为是过程的一部分,所以 ProcOfLine 属性可能会返回过程主体之外的行的过程名称。ProcStartLine 属性指明过程的起始行,ProcBodyLine 属性指出过程定义的起始行(过程的主体)。
请注意,pprockind 参数指明行是属于某个 Sub 或 Function 过程、Property Get 过程、Property Let 过程还是某个 Property Set 过程。如果要确定该行所在过程的类型,请将类型为 Long 的变量传递给 ProcOfLine 属性,然后检查该变量的值。
注释 ProcBodyLine 属性不区分 Sub 和 Function 过程,但是区分 Property 过程的每一类型。
下面的函数过程列出指定模块中所有过程的名称。
Public Function AllProcs(ByVal strModuleName As String)
Dim mdl As Module
Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim astrProcNames() As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long
' Open specified Module object.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Count lines in module.
lngCount = mdl.CountOfLines
' Count lines in Declaration section in module.
lngCountDecl = mdl.CountOfDeclarationLines
' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
' Initialize counter variable.
intI = 0
' Redimension array.
ReDim Preserve astrProcNames(intI)
' Store name of first procedure in array.
astrProcNames(intI) = strProcName
' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1 To lngCount
' Compare procedure name with ProcOfLine property value.
If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
' Increment counter.
intI = intI + 1
strProcName = mdl.ProcOfLine(lngI, lngR)
ReDim Preserve astrProcNames(intI)
' Assign unique procedure names to array.
astrProcNames(intI) = strProcName
End If
Next lngI
strMsg = "Procedures in module '" & strModuleName & "': " & vbCrLf & vbCrLf
For intI = 0 To UBound(astrProcNames)
strMsg = strMsg & astrProcNames(intI) & vbCrLf
Next intI
' Message box listing all procedures in module.
MsgBox strMsg
End Function
可以用如下过程来调用该函数:
Public Sub GetAllProcs()
AllProcs "Utility Functions"
End Sub