Module.ProcOfLine 属性 (Access)

ProcOfLine 属性返回包含在标准模块或类模块中的指定的行的过程的名称。 只读 String 即字符串类型。

语法

表达式ProcOfLine (LineProcKind)

表达 一个代表 Module 对象的变量。

参数

名称 必需/可选 数据类型 说明
Line 必需 Long 模块中的行号。
ProcKind 必需 vbext_ProcKind 过程的类型。 有关可能的设置,请参阅“备注”部分。

备注

ProcKind 参数可以是以下 vbext_ProcKind 常量之一:

常量 说明
vbext_pk_Get Get 属性 过程。
vbext_pk_Let Let 属性 过程。
vbext_pk_Proc 子程序函数 的过程。
vbext_pk_Set 设置属性 的过程。

对于任何给定的行号, ProcOfLine 属性返回包含该行的过程的名称。 由于过程定义前面的注释和编译常量被视为该过程的一部分, 因此 ProcOfLine 属性可能会返回不在过程正文中的行的过程名称。

ProcStartLine 属性指示的行开始一个过程; ProcBodyLine 属性表示的过程定义开始 (过程的主体) 的行。

请注意, ProcKind 参数指示行属于 SubFunction 过程、 Property Get 过程、 Property Let 过程还是 属性集 过程。 若要确定行所使用的过程类型,请将 Long 类型的变量传递给 ProcOfLine 属性,然后检查该变量的值。

注意

ProcOfLine 属性以类似的方式对待 SubFunction 过程,但区分了每种类型的 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

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。