ProcOfLine 屬性返回一個(gè)只讀字符串,該字符串包含標(biāo)準(zhǔn)模塊或類(lèi)模塊中指定行所在過(guò)程的名稱(chēng)。
expression.ProcOfLine(Line, pprockind)
expression 必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。
Line 必需 Long 型。模塊中的行號(hào)。
pprockind 必需 vbext_ProcKind 型。是包含 Line 參數(shù)指定行的過(guò)程的類(lèi)型。該常量可以是下列值之一:
常量 |
說(shuō)明 |
vbext_pk_Get |
Property Get 過(guò)程。 |
vbext_pk_Let |
Property Let 過(guò)程。 |
vbext_pk_Proc |
Sub 或 Function 過(guò)程。 |
vbext_pk_Set |
Property Set 過(guò)程。 |
ProcOfLine 屬性?xún)H在使用 Visual Basic 時(shí)才可用。
對(duì)于任何給定的行號(hào),ProcOfLine 屬性返回包含該行的過(guò)程的名稱(chēng)。因?yàn)檫^(guò)程定義之前的說(shuō)明語(yǔ)句和編譯常量被認(rèn)為是過(guò)程的一部分,所以 ProcOfLine 屬性可能會(huì)返回過(guò)程主體之外的行的過(guò)程名稱(chēng)。ProcStartLine 屬性指明過(guò)程的起始行,ProcBodyLine 屬性指出過(guò)程定義的起始行(過(guò)程的主體)。
請(qǐng)注意,pprockind 參數(shù)指明行是屬于某個(gè) Sub 或 Function 過(guò)程、Property Get 過(guò)程、Property Let 過(guò)程還是某個(gè) Property Set 過(guò)程。如果要確定該行所在過(guò)程的類(lèi)型,請(qǐng)將類(lèi)型為 Long 的變量傳遞給 ProcOfLine 屬性,然后檢查該變量的值。
注釋 ProcBodyLine 屬性不區(qū)分 Sub 和 Function 過(guò)程,但是區(qū)分 Property 過(guò)程的每一類(lèi)型。
下面的函數(shù)過(guò)程列出指定模塊中所有過(guò)程的名稱(chēng)。
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
可以用如下過(guò)程來(lái)調(diào)用該函數(shù):
Public Sub GetAllProcs()
AllProcs "Utility Functions"
End Sub