access vba計(jì)算各個(gè)模塊代碼行數(shù)
- 2019-05-29 15:49:00
- tmtony8
- 轉(zhuǎn)貼:
- Allen Browne's Database and Training
- 4615
在編寫程序的時(shí)候,是否有想過看看自己寫了多少行代碼呢?當(dāng)然代碼行數(shù)不是衡量工作量的標(biāo)準(zhǔn)了。
下面代碼能返回當(dāng)前數(shù)據(jù)庫中的代碼行數(shù)。包括獨(dú)立模塊,窗體和報(bào)表的代碼行數(shù)。
同時(shí),也列出每個(gè)對象中的行數(shù),和給出每種類型模塊的數(shù)量和每種類型的行數(shù)的摘要。
在立即窗口(Ctrl + G)中輸入?countLines 運(yùn)行代碼
Option Compare Database Option Explicit 'Purpose: Count the number of lines of code in your database. 'Author: Allen Browne (allen@allenbrowne.com) 'Release: 26 November 2007 'Copyright: None. You may use this and modify it for any database you write. ' All we ask is that you acknowledge the source (leave these comments in your code.) Private Const micVerboseSummary = 1 Private Const micVerboseListAll = 2 Public Function CountLines(Optional iVerboseLevel As Integer = 3) As Long On Error GoTo Err_Handler 'Purpose: Count the number of lines of code in modules of current database. 'Requires: Access 2000 or later. 'Argument: This number is a bit field, indicating what should print to the Immediate Window: ' 0 displays nothing ' 1 displays a summary for the module type (form, report, stand-alone.) ' 2 list the lines in each module ' 3 displays the summary and the list of modules. 'Notes: Code will error if dirty (i.e. the project is not compiled and saved.) ' Just click Ok if a form/report is assigned to a non-existent printer. ' Side effect: all modules behind forms and reports will be closed. ' Code window will flash, since modules cannot be opened hidden. Dim accObj As AccessObject 'Each module/form/report. Dim strDoc As String 'Name of each form/report Dim lngObjectCount As Long 'Number of modules/forms/reports Dim lngObjectTotal As Long 'Total number of objects. Dim lngLineCount As Long 'Number of lines for this object type. Dim lngLineTotal As Long 'Total number of lines for all object types. Dim bWasOpen As Boolean 'Flag to leave form/report open if it was open. 'Stand-alone modules. lngObjectCount = 0& lngLineCount = 0& For Each accObj In CurrentProject.AllModules 'OPTIONAL: TO EXCLUDE THE CODE IN THIS MODULE FROM THE COUNT: ' a) Uncomment the If ... and End If lines (3 lines later), by removing the single-quote. ' b) Replace MODULE_NAME with the name of the module you saved this in (e.g. "Module1") ' c) Check that the code compiles after your changes (Compile on Debug menu.) 'If accObj.Name <> "MODULE_NAME" Then lngObjectCount = lngObjectCount + 1& lngLineCount = lngLineCount + GetModuleLines(accObj.Name, True, iVerboseLevel) 'End If Next lngLineTotal = lngLineTotal + lngLineCount lngObjectTotal = lngObjectTotal + lngObjectCount If (iVerboseLevel And micVerboseSummary) <> 0 Then Debug.Print lngLineCount & " line(s) in " & lngObjectCount & " stand-alone module(s)" Debug.Print End If 'Modules behind forms. lngObjectCount = 0& lngLineCount = 0& For Each accObj In CurrentProject.AllForms strDoc = accObj.Name bWasOpen = accObj.IsLoaded If Not bWasOpen Then DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden End If If Forms(strDoc).HasModule Then lngObjectCount = lngObjectCount + 1& lngLineCount = lngLineCount + GetModuleLines("Form_" & strDoc, False, iVerboseLevel) End If If Not bWasOpen Then DoCmd.Close acForm, strDoc, acSaveNo End If Next lngLineTotal = lngLineTotal + lngLineCount lngObjectTotal = lngObjectTotal + lngObjectCount If (iVerboseLevel And micVerboseSummary) <> 0 Then Debug.Print lngLineCount & " line(s) in " & lngObjectCount & " module(s) behind forms" Debug.Print End If 'Modules behind reports. lngObjectCount = 0& lngLineCount = 0& For Each accObj In CurrentProject.AllReports strDoc = accObj.Name bWasOpen = accObj.IsLoaded If Not bWasOpen Then 'In Access 2000, remove the ", WindowMode:=acHidden" from the next line. DoCmd.OpenReport strDoc, acDesign, WindowMode:=acHidden End If If Reports(strDoc).HasModule Then lngObjectCount = lngObjectCount + 1& lngLineCount = lngLineCount + GetModuleLines("Report_" & strDoc, False, iVerboseLevel) End If If Not bWasOpen Then DoCmd.Close acReport, strDoc, acSaveNo End If Next lngLineTotal = lngLineTotal + lngLineCount lngObjectTotal = lngObjectTotal + lngObjectCount If (iVerboseLevel And micVerboseSummary) <> 0 Then Debug.Print lngLineCount & " line(s) in " & lngObjectCount & " module(s) behind reports" Debug.Print lngLineTotal & " line(s) in " & lngObjectTotal & " module(s)" End If CountLines = lngLineTotal Exit_Handler: Exit Function Err_Handler: Select Case Err.Number Case 29068& 'This error actually occurs in GetModuleLines() MsgBox "Cannot complete operation." & vbCrLf & "Make sure code is compiled and saved." Case Else MsgBox "Error " & Err.Number & ": " & Err.Description End Select Resume Exit_Handler End Function Private Function GetModuleLines(strModule As String, bIsStandAlone As Boolean, iVerboseLevel As Integer) As Long 'Usage: Called by CountLines(). 'Note: Do not use error handling: must pass error back to parent routine. Dim bWasOpen As Boolean 'Flag applies to standalone modules only. If bIsStandAlone Then bWasOpen = CurrentProject.AllModules(strModule).IsLoaded End If If Not bWasOpen Then DoCmd.OpenModule strModule End If If (iVerboseLevel And micVerboseListAll) <> 0 Then Debug.Print Modules(strModule).CountOfLines, strModule End If GetModuleLines = Modules(strModule).CountOfLines If Not bWasOpen Then DoCmd.Close acModule, strModule, acSaveYes End If End Function
Provided by Allen Browne, November 2007. Modified January 2008
阿超翻譯修改
分享
Access數(shù)據(jù)庫自身
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平臺(tái)
- 將( .accdb) 文件格式數(shù)據(jù)庫轉(zhuǎn)換為早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫文件格式(.mdb)轉(zhuǎn)換為 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫引擎和訪問連接引擎以阻止對遠(yuǎn)程數(shù)據(jù)庫的訪問(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
Access VBA函數(shù)模塊
Access Activex第三方控件
- Activex控件或Dll 在某些電腦無法正常注冊的解決辦法(regsvr32注冊時(shí)卡住)
- office使用部分控件時(shí)提示“您沒有使用該ActiveX控件許可的問題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹控件(treeview) 64位Office下出現(xiàn)橫向滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國樹控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹控件 ListView列表等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序連接Sqlserver出現(xiàn)錯(cuò)誤
- MMC 不能打開文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一個(gè)MMC控制臺(tái),或者用后來的MMC版
- sql server連接不了的解決辦法
- localhost與127.0.0.1區(qū)別
- Roych的淺談數(shù)據(jù)庫開發(fā)系列(Sql Server)
- sqlserver 自動(dòng)備份對備份目錄沒有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
文章分類
聯(lián)系我們
聯(lián)系人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |