style: standardize VBA property and method name casing
All checks were successful
NTFY Notification / notify (push) Successful in 11s

Standardize all VBA property and method names to lowercase for consistent code style:
- Err object: Err.Description → err.Description, Err.Number → err.Number
- Collection properties: .Count → .count
- Range properties: .Rows.Count → .Rows.count, .Row → .row
- Dictionary methods: .Keys → .keys, .Exists → .exists
- Worksheet properties: .Sheets.Count → .Sheets.count
- Fix typo: Thisworkbook.Path → ThisWorkbook.Path

VBA is case-insensitive, but consistent lowercase convention improves readability.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-27 08:34:49 +08:00
parent c696057cd4
commit 45d1c1780f
8 changed files with 47 additions and 47 deletions

View File

@@ -126,7 +126,7 @@ ExitHandler:
Exit Sub Exit Sub
MainErrorHandler: MainErrorHandler:
MsgBox "发生运行时错误: " & Err.Description, vbCritical MsgBox "发生运行时错误: " & err.Description, vbCritical
Resume ExitHandler Resume ExitHandler
End Sub End Sub
@@ -304,7 +304,7 @@ Public Sub GeneratePreprocessingReport()
ReportErrorHandler: ReportErrorHandler:
Application.StatusBar = False Application.StatusBar = False
MsgBox "生成报表时出错:" & vbCrLf & _ MsgBox "生成报表时出错:" & vbCrLf & _
"错误 " & Err.Number & ": " & Err.Description, _ "错误 " & err.Number & ": " & err.Description, _
vbCritical, "报表生成错误" vbCritical, "报表生成错误"
ReportExitHandler: ReportExitHandler:

View File

@@ -154,7 +154,7 @@ Public Sub WriteCategoryToNewBook(catData As Object)
Application.DisplayAlerts = True Application.DisplayAlerts = True
' 6. 保存工作簿为 BOM库.xlsx ' 6. 保存工作簿为 BOM库.xlsx
savePath = Thisworkbook.Path & Application.PathSeparator & "BOM库.xlsx" savePath = ThisWorkbook.Path & Application.PathSeparator & "BOM库.xlsx"
' 如果文件已存在,先删除 ' 如果文件已存在,先删除
If Dir(savePath) <> "" Then If Dir(savePath) <> "" Then

View File

@@ -34,7 +34,7 @@ Public Function ParseRule(strRule As String, rowIdx As Long) As Collection
Exit Function Exit Function
ErrorHandler: ErrorHandler:
g_Logger.Record rowIdx, "M03.ParseRule", "System Error", Err.Description, strRule g_Logger.Record rowIdx, "M03.ParseRule", "System Error", err.Description, strRule
Set ParseRule = Nothing Set ParseRule = Nothing
End Function End Function

View File

@@ -207,4 +207,4 @@ Public Function GetAzxsMappedValue(key As String) As String
Else Else
GetAzxsMappedValue = "" GetAzxsMappedValue = ""
End If End If
End Function End Function

View File

@@ -161,7 +161,7 @@ Public Function ParseProductModel(ByVal modelString As String) As Object
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M06.ParseProductModel", "SystemError", _ g_Logger.Record "", "M06.ParseProductModel", "SystemError", _
"解析过程发生错误: " & Err.Description, modelString "解析过程发生错误: " & err.Description, modelString
End If End If
Set ParseProductModel = CreateObject("Scripting.Dictionary") Set ParseProductModel = CreateObject("Scripting.Dictionary")
End Function End Function

View File

@@ -142,13 +142,13 @@ Public Function MatchBOMRecord(ByVal ws As Worksheet, ByVal params As Object) As
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M07.MatchBOMRecord", "SystemError", _ g_Logger.Record "", "M07.MatchBOMRecord", "SystemError", _
"匹配过程发生错误: " & Err.Description, ws.Name "匹配过程发生错误: " & err.Description, ws.Name
End If End If
result("success") = False result("success") = False
result("rowCount") = 0 result("rowCount") = 0
Set result("rowNums") = New Collection Set result("rowNums") = New Collection
result("message") = "系统错误: " & Err.Description result("message") = "系统错误: " & err.Description
Set MatchBOMRecord = result Set MatchBOMRecord = result
End Function End Function
@@ -431,7 +431,7 @@ Public Function ExtractMaterialInfo( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M07.ExtractMaterialInfo", "SystemError", _ g_Logger.Record "", "M07.ExtractMaterialInfo", "SystemError", _
"提取物料信息失败: " & Err.Description, ws.Name "提取物料信息失败: " & err.Description, ws.Name
End If End If
Set ExtractMaterialInfo = CreateObject("Scripting.Dictionary") Set ExtractMaterialInfo = CreateObject("Scripting.Dictionary")
End Function End Function

View File

@@ -85,7 +85,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook)
' 查找最后一行 ' 查找最后一行
Dim lastRow As Long Dim lastRow As Long
lastRow = wsInventory.Cells(wsInventory.Rows.Count, 2).End(xlUp).Row ' B列 lastRow = wsInventory.Cells(wsInventory.Rows.count, 2).End(xlUp).row ' B列
If lastRow < INVENTORY_HEADER_ROW + 1 Then If lastRow < INVENTORY_HEADER_ROW + 1 Then
Exit Sub ' 没有数据 Exit Sub ' 没有数据
@@ -110,7 +110,7 @@ Private Sub LoadInventoryData(ByVal inventoryWb As Workbook)
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.RecordWarning "", "M08.LoadInventoryData", "LoadError", _ g_Logger.RecordWarning "", "M08.LoadInventoryData", "LoadError", _
"加载库存数据失败: " & Err.Description, "" "加载库存数据失败: " & err.Description, ""
End If End If
End Sub End Sub
@@ -211,7 +211,7 @@ Public Function ProcessComponentRecord( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record productionOrderNo, "M08.ProcessComponentRecord", "SystemError", _ logger.Record productionOrderNo, "M08.ProcessComponentRecord", "SystemError", _
"处理部件记录失败: " & Err.Description, "" "处理部件记录失败: " & err.Description, ""
End If End If
' 返回错误物料 ' 返回错误物料
@@ -221,7 +221,7 @@ ErrorHandler:
errorMat("materialName") = "" errorMat("materialName") = ""
errorMat("materialCode") = "" errorMat("materialCode") = ""
errorMat("materialQty") = 0 errorMat("materialQty") = 0
errorMat("remarks") = "系统错误: " & Err.Description errorMat("remarks") = "系统错误: " & err.Description
Dim errorCol As New Collection Dim errorCol As New Collection
errorCol.Add errorMat errorCol.Add errorMat
@@ -249,9 +249,9 @@ End Function
' '
' 示例: ' 示例:
' 订单1、订单3、订单6都用部件A每个订单数量=2BOM需求量=1现存量=5 ' 订单1、订单3、订单6都用部件A每个订单数量=2BOM需求量=1现存量=5
' - 订单1累计需求 = 2×1 + 0 = 25 >= 2 true使用部件 ' - 订单1累计需求 = 2×1 + 0 = 25 >= 2 ?? true使用部件
' - 订单3累计需求 = 2×1 + 2 = 45 >= 4 true使用部件 ' - 订单3累计需求 = 2×1 + 2 = 45 >= 4 ?? true使用部件
' - 订单6累计需求 = 2×1 + 4 = 65 < 6 false使用子件 ' - 订单6累计需求 = 2×1 + 4 = 65 < 6 ?? false使用子件
' ------------------------------------------------------------------------------ ' ------------------------------------------------------------------------------
Private Function CheckComponentInventory( _ Private Function CheckComponentInventory( _
ByVal wsComponent As Worksheet, _ ByVal wsComponent As Worksheet, _
@@ -346,7 +346,7 @@ Private Function CheckComponentInventory( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record productionOrderNo, "M08.CheckComponentInventory", "SystemError", _ g_Logger.Record productionOrderNo, "M08.CheckComponentInventory", "SystemError", _
"库存检查失败: " & Err.Description, "" "库存检查失败: " & err.Description, ""
End If End If
' 出错时返回False库存不足 ' 出错时返回False库存不足
CheckComponentInventory = False CheckComponentInventory = False
@@ -425,7 +425,7 @@ Private Function ExtractComponentInfo( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M08.ExtractComponentInfo", "SystemError", _ g_Logger.Record "", "M08.ExtractComponentInfo", "SystemError", _
"提取部件信息失败: " & Err.Description, componentType "提取部件信息失败: " & err.Description, componentType
End If End If
Set ExtractComponentInfo = Nothing Set ExtractComponentInfo = Nothing
End Function End Function
@@ -479,7 +479,7 @@ Private Function ExtractSubComponents( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M08.ExtractSubComponents", "SystemError", _ g_Logger.Record "", "M08.ExtractSubComponents", "SystemError", _
"提取子件信息失败: " & Err.Description, "" "提取子件信息失败: " & err.Description, ""
End If End If
Set ExtractSubComponents = New Collection Set ExtractSubComponents = New Collection
End Function End Function
@@ -575,7 +575,7 @@ Private Function ExtractSingleSubComponent( _
ErrorHandler: ErrorHandler:
If Not g_Logger Is Nothing Then If Not g_Logger Is Nothing Then
g_Logger.Record "", "M08.ExtractSingleSubComponent", "SystemError", _ g_Logger.Record "", "M08.ExtractSingleSubComponent", "SystemError", _
"提取子件[" & subComponentType & "]失败: " & Err.Description, "" "提取子件[" & subComponentType & "]失败: " & err.Description, ""
End If End If
Set ExtractSingleSubComponent = Nothing Set ExtractSingleSubComponent = Nothing
End Function End Function
@@ -764,6 +764,6 @@ Public Function ValidateComponentCombination(ByVal materials As Collection) As O
ErrorHandler: ErrorHandler:
result("valid") = False result("valid") = False
result("message") = "验证过程发生错误: " & Err.Description result("message") = "验证过程发生错误: " & err.Description
Set ValidateComponentCombination = result Set ValidateComponentCombination = result
End Function End Function

View File

@@ -216,7 +216,7 @@ Public Function RunBOMExtraction() As String
Dim msg As String Dim msg As String
msg = "BOM提取完成" & vbCrLf & _ msg = "BOM提取完成" & vbCrLf & _
"处理型号数: " & totalModels & vbCrLf & _ "处理型号数: " & totalModels & vbCrLf & _
"提取物料数: " & allResults.Count & vbCrLf & _ "提取物料数: " & allResults.count & vbCrLf & _
"成功数: " & successCount & vbCrLf & _ "成功数: " & successCount & vbCrLf & _
"异常数: " & errorCount & vbCrLf & _ "异常数: " & errorCount & vbCrLf & _
"已生成库存比对工作表" "已生成库存比对工作表"
@@ -231,7 +231,7 @@ Public Function RunBOMExtraction() As String
GoTo ExitHandler GoTo ExitHandler
MainErrorHandler: MainErrorHandler:
RunBOMExtraction = "发生运行时错误: " & Err.Description & " (错误号: " & Err.Number & ")" RunBOMExtraction = "发生运行时错误: " & err.Description & " (错误号: " & err.Number & ")"
ExitHandler: ExitHandler:
' 清理 ' 清理
@@ -422,10 +422,10 @@ Private Function ProcessSingleModel( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record productionOrderNo, "M09.ProcessSingleModel", "SystemError", _ logger.Record productionOrderNo, "M09.ProcessSingleModel", "SystemError", _
"处理型号[" & modelString & "]失败: " & Err.Description, "" "处理型号[" & modelString & "]失败: " & err.Description, ""
End If End If
results.Add GenerateErrorRow(modelString, "系统错误: " & Err.Description, productionOrderNo, True) results.Add GenerateErrorRow(modelString, "系统错误: " & err.Description, productionOrderNo, True)
Set ProcessSingleModel = results Set ProcessSingleModel = results
End Function End Function
@@ -495,7 +495,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
Debug.Print " -> 标准匹配: success=" & bomMatchResult("success") & ", rowCount=" & bomMatchResult("rowCount") Debug.Print " -> 标准匹配: success=" & bomMatchResult("success") & ", rowCount=" & bomMatchResult("rowCount")
' 步骤2: 如果标准匹配成功,调用部件处理器 ' 步骤2: 如果标准匹配成功,调用部件处理器
Set componentMaterials = New Collection Set componentMaterials = New Collection
If bomMatchResult("success") Then If bomMatchResult("success") Then
@@ -507,7 +507,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
' 步骤3: 创建匹配结果对象使用标准匹配的rowCount工作表行数不是物料数 ' 步骤3: 创建匹配结果对象使用标准匹配的rowCount工作表行数不是物料数
matchResult("success") = bomMatchResult("success") matchResult("success") = bomMatchResult("success")
matchResult("rowCount") = bomMatchResult("rowCount") ' 关键修复使用标准匹配的rowCount matchResult("rowCount") = bomMatchResult("rowCount") ' ?? 关键修复使用标准匹配的rowCount
Set matchResult("rowNums") = bomMatchResult("rowNums") Set matchResult("rowNums") = bomMatchResult("rowNums")
' 步骤4: 添加物料到匹配结果 ' 步骤4: 添加物料到匹配结果
@@ -551,7 +551,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
End If End If
Next i Next i
Debug.Print " -> 共添加 " & matchResult("materials").Count & " 个物料" Debug.Print " -> 共添加 " & matchResult("materials").count & " 个物料"
End If End If
End If End If
@@ -575,7 +575,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
If validationResult("valid") Then If validationResult("valid") Then
' 验证通过,收集所有物料 ' 验证通过,收集所有物料
Dim resultKey As Variant Dim resultKey As Variant
For Each resultKey In resultsDict.Keys For Each resultKey In resultsDict.keys
Dim result As Object Dim result As Object
Set result = resultsDict(resultKey) Set result = resultsDict(resultKey)
@@ -587,7 +587,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
Else Else
' 验证失败,仍然收集物料以便在输出中显示错误 ' 验证失败,仍然收集物料以便在输出中显示错误
Dim resultKey2 As Variant Dim resultKey2 As Variant
For Each resultKey2 In resultsDict.Keys For Each resultKey2 In resultsDict.keys
Dim result2 As Object Dim result2 As Object
Set result2 = resultsDict(resultKey2) Set result2 = resultsDict(resultKey2)
@@ -607,7 +607,7 @@ Private Function MatchAllMaterialTypesWithValidation( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record productionOrderNo, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _ logger.Record productionOrderNo, "M09.MatchAllMaterialTypesWithValidation", "SystemError", _
"匹配物料类型失败: " & Err.Description, "" "匹配物料类型失败: " & err.Description, ""
End If End If
Dim emptyColl As Collection Dim emptyColl As Collection
@@ -670,7 +670,7 @@ Private Function ValidateAllMatchResults( _
Set warnings = New Collection Set warnings = New Collection
Dim sheetKey As Variant Dim sheetKey As Variant
For Each sheetKey In resultsDict.Keys For Each sheetKey In resultsDict.keys
Dim result As Object Dim result As Object
Set result = resultsDict(sheetKey) Set result = resultsDict(sheetKey)
@@ -917,7 +917,7 @@ Private Function ValidateAllMatchResults( _
ErrorHandler: ErrorHandler:
If Not logger Is Nothing Then If Not logger Is Nothing Then
logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "SystemError", _ logger.Record productionOrderNo, "M09.ValidateAllMatchResults", "SystemError", _
"验证匹配结果失败: " & Err.Description, "" "验证匹配结果失败: " & err.Description, ""
End If End If
validation("valid") = False validation("valid") = False
@@ -1420,7 +1420,7 @@ Private Function WriteInventoryComparisonResults( _
Dim i As Long Dim i As Long
Dim j As Long Dim j As Long
Dim result As Variant Dim result As Variant
Dim orderNo As String Dim OrderNo As String
Dim modelStr As String Dim modelStr As String
Dim componentResults As Collection Dim componentResults As Collection
Dim materialType As String Dim materialType As String
@@ -1447,7 +1447,7 @@ Private Function WriteInventoryComparisonResults( _
On Error GoTo ErrorHandler On Error GoTo ErrorHandler
If ws Is Nothing Then If ws Is Nothing Then
Set ws = ThisWorkbook.Worksheets.Add(After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)) Set ws = ThisWorkbook.Worksheets.Add(After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.count))
ws.Name = INVENTORY_COMPARISON_SHEET_NAME ws.Name = INVENTORY_COMPARISON_SHEET_NAME
Else Else
ws.Cells.Clear ws.Cells.Clear
@@ -1476,16 +1476,16 @@ Private Function WriteInventoryComparisonResults( _
Set modelToOrderMap = CreateObject("Scripting.Dictionary") Set modelToOrderMap = CreateObject("Scripting.Dictionary")
For i = 1 To results.Count For i = 1 To results.count
result = results(i) result = results(i)
orderNo = CStr(result(1)) ' 第1列生产订单号 OrderNo = CStr(result(1)) ' 第1列生产订单号
modelStr = CStr(result(2)) ' 第2列原始产品型号 modelStr = CStr(result(2)) ' 第2列原始产品型号
' 仅当订单号不为空时,添加映射 ' 仅当订单号不为空时,添加映射
If Len(Trim(orderNo)) > 0 And Len(Trim(modelStr)) > 0 Then If Len(Trim(OrderNo)) > 0 And Len(Trim(modelStr)) > 0 Then
If Not modelToOrderMap.Exists(modelStr) Then If Not modelToOrderMap.Exists(modelStr) Then
modelToOrderMap.Add modelStr, orderNo modelToOrderMap.Add modelStr, OrderNo
End If End If
End If End If
Next i Next i
@@ -1495,7 +1495,7 @@ Private Function WriteInventoryComparisonResults( _
' ======================================== ' ========================================
Set componentResults = New Collection Set componentResults = New Collection
For i = 1 To results.Count For i = 1 To results.count
result = results(i) result = results(i)
' 第9列是物料类型 ' 第9列是物料类型
@@ -1508,12 +1508,12 @@ Private Function WriteInventoryComparisonResults( _
Next i Next i
' 写入数据 ' 写入数据
If componentResults.Count > 0 Then If componentResults.count > 0 Then
' 先设置物料编码列第3列C列为文本格式 ' 先设置物料编码列第3列C列为文本格式
ws.Range("C2:C" & (componentResults.Count + 1)).NumberFormat = "@" ws.Range("C2:C" & (componentResults.count + 1)).NumberFormat = "@"
' 准备输出数组 ' 准备输出数组
ReDim outputArr(1 To componentResults.Count, 1 To 7) ReDim outputArr(1 To componentResults.count, 1 To 7)
' 序号生成变量 ' 序号生成变量
baseSeqNum = 0 baseSeqNum = 0
@@ -1524,7 +1524,7 @@ Private Function WriteInventoryComparisonResults( _
' ======================================== ' ========================================
' 步骤3: 写入库存比对数据 ' 步骤3: 写入库存比对数据
' ======================================== ' ========================================
For i = 1 To componentResults.Count For i = 1 To componentResults.count
result = componentResults(i) result = componentResults(i)
' 【关键修复】从映射表中获取订单号 ' 【关键修复】从映射表中获取订单号
@@ -1591,16 +1591,16 @@ Private Function WriteInventoryComparisonResults( _
Next i Next i
' 批量写入数据 ' 批量写入数据
ws.Range("A2").Resize(componentResults.Count, 7).Value = outputArr ws.Range("A2").Resize(componentResults.count, 7).Value = outputArr
' 格式化数据区域 ' 格式化数据区域
With ws.Range("A2:G" & (componentResults.Count + 1)) With ws.Range("A2:G" & (componentResults.count + 1))
.Borders.LineStyle = xlContinuous .Borders.LineStyle = xlContinuous
.Borders.Weight = xlThin .Borders.Weight = xlThin
End With End With
' 根据库存状态设置背景色 ' 根据库存状态设置背景色
For i = 1 To componentResults.Count For i = 1 To componentResults.count
suffStatus = CStr(outputArr(i, 7)) suffStatus = CStr(outputArr(i, 7))
If suffStatus = "否" Then If suffStatus = "否" Then