fix: resolve duplicate variable declaration compilation errors
All checks were successful
NTFY Notification / notify (push) Successful in 5s

- Move shouldExclude declaration to function level in MatchAllMaterialTypesWithValidation
- Move rawMat and result declarations to function level in BOMExtraction
- Remove duplicate Dim statements inside loops

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-27 13:22:10 +08:00
parent dd931eba53
commit 314c9baefe

View File

@@ -127,6 +127,8 @@ Public Function BOMExtraction() As String
Dim i As Long
Dim totalModels As Long
Dim rawMat As Variant ' 在函数级别声明一次
Dim result As Variant ' 在函数级别声明一次
totalModels = UBound(inputModels, 1)
For i = LBound(inputModels, 1) To UBound(inputModels, 1)
@@ -159,13 +161,11 @@ Public Function BOMExtraction() As String
Set modelResults = ProcessSingleModel(modelString, g_BOMWorkbook, g_Logger, productionOrderNo, orderQty, rawMaterials)
' 收集未过滤的物料(用于库存比对)
Dim rawMat As Variant
For Each rawMat In rawMaterials
allRawMaterials.Add rawMat
Next rawMat
' 合并已过滤的结果用于BOM提取结果和BIP上传
Dim result As Variant
For Each result In modelResults
allResults.Add result
Next result
@@ -196,7 +196,6 @@ Public Function BOMExtraction() As String
Dim componentMaterials As Collection
Set componentMaterials = New Collection
Dim rawMat As Variant
For Each rawMat In allRawMaterials
If rawMat("materialType") = "部件" Then
componentMaterials.Add rawMat
@@ -621,6 +620,9 @@ Private Function MatchAllMaterialTypesWithValidation( _
' 初始化未过滤集合(用于库存比对工作表)
Set outRawMaterials = New Collection
' 声明过滤标志变量(在函数级别声明一次)
Dim shouldExclude As Boolean
If validationResult("valid") Then
' 验证通过,收集所有物料
Dim resultKey As Variant
@@ -634,7 +636,6 @@ Private Function MatchAllMaterialTypesWithValidation( _
outRawMaterials.Add mat
' 2. 添加到已过滤集合(排除库存不足的部件标记)
Dim shouldExclude As Boolean
shouldExclude = False
If mat.Exists("isStockSufficient") Then
@@ -661,7 +662,6 @@ Private Function MatchAllMaterialTypesWithValidation( _
outRawMaterials.Add mat2
' 2. 添加到已过滤集合(排除库存不足的部件标记)
Dim shouldExclude As Boolean
shouldExclude = False
If mat2.Exists("isStockSufficient") Then