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

View File

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

View File

@@ -34,7 +34,7 @@ Public Function ParseRule(strRule As String, rowIdx As Long) As Collection
Exit Function
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
End Function

View File

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

View File

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

View File

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

View File

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

View File

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