VBA代码编程方法详解(九)
时 间:2010-10-30 00:02:08
作 者:江羽 ID:3967 城市:南昌
摘 要:VBA代码编程方法详解(第九部分)
正 文:
6.6 获取部件或模块中代码行信息
'函数功能:获得指定部件或模块中申明部分总代码行数(含注释行及空行)
Public Function TotalDeclLinesInVBComp (CompsNameOrIndex) As Long
Dim VBProj As VBProject '申明工程项目对象
Dim VBComp As VBComponent '申明项目组件对象
Dim CodeMod As CodeModule '申明组件代码
'实例化对象
Set VBProj = VBE.ActiveVBProject
Set VBComp = VBProj.VBComponents(CompsNameOrIndex)
Set CodeMod = VBComp.CodeModule
'获得申明代码行数并输出
TotalDeclLinesInVBComp = CodeMod.CountOfDeclarationLines
End Function
'******************************************************************
'调用示例:获得部件"bas_ProcInfo"模块中申明部分总代码行数
Debug.Print TotalDeclLinesInVBComp ("bas_ProcInfo")
'函数功能:获得指定模块中总代码行数(含申明代码行、注释行及空行)
Public Function TotalCodeLinesInVBComp (CompsNameOrIndex) As Long
Dim VBProj As VBProject
Dim VBComp As VBComponent
Dim CodeMod As CodeModule
'实例化对象
Set VBProj = VBE.ActiveVBProject
Set VBComp = VBProj.VBComponents(CompsNameOrIndex)
Set CodeMod = VBComp.CodeModule
'获得部件或模块中代码总行数并输出
TotalCodeLinesInVBComp = CodeMod.CountOfLines
End Function
'******************************************************************
'调用示例:获得部件"bas_ProcInfo"模块中总代码行数
Debug.Print TotalCodeLinesInVBComp ("bas_ProcInfo")
'函数功能:获得指定部件或模块代码数。包括申明及代码,但不含注释代码行及空白行
Public Function CodeLinesInVBComp (CompsNameOrIndex) As Long
Dim VBProj As VBProject
Dim VBComp As VBComponent
Dim CodeMod As CodeModule
Dim I As Long
Dim strCode As String
Dim LineCount As Long
'实例化对象
Set VBProj = VBE.ActiveVBProject
Set VBComp = VBProj.VBComponents(CompsNameOrIndex)
Set CodeMod = VBComp.CodeModule
With CodeMod
'循环每行代码
For I = 1 To .CountOfLines
'将代码赋值给字符串变量
strCode = .Lines(I, 1)
If Trim (strCode) = vbNullString or Left (Trim (strCode), 1) = Chr (39) Then
'跳过空行注释行
Else
LineCount = LineCount + 1
End If
Next I
End With
'获取实际代码计数输出
CodeLinesInVBComp = LineCount
End Function
'******************************************************************
'调用示例:获得部件"bas_ProcInfo"模块中实际代码行数
Debug.Print CodeLinesInVBComp ("bas_ProcInfo")
6.7 获取工程代码行数信息
'函数功能:工程总代码行数(含空及注释)
'调 用:TotalCodeLinesInVBComp
Public Function TotalCodeLinesInProject () As Long
Dim VBProj As VBProject
Dim VBComp As VBComponent
Dim LineCount As Long
Set VBProj = VBE.ActiveVBProject
'判断工程是否锁定,则退出函数,
If VBProj.Protection = vbext_pp_locked Then
TotalCodeLinesInProject = -1
Exit Function
End If
'遍历当前工程中所有部件
For Each VBComp In VBProj.VBComponents
LineCount = LineCount + TotalCodeLinesInVBComp(VBComp.Name)
Next VBComp
TotalCodeLinesInProject = LineCount
End Function
'函数功能:工程实际代码行数(不含空及注释)
'调 用:CodeLinesInVBComp
Public Function CodeLinesInProject() As Long
Dim VBProj As VBProject
Dim VBComp As VBComponent
Dim LineCount As Long
Set VBProj = VBE.ActiveVBProject
'遍历当前工程中所有部件对象
For Each VBComp In VBProj.VBComponents
LineCount = LineCount + CodeLinesInVBComp(VBComp.Name)
Next VBComp
CodeLinesInProject = LineCount
End Function
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)