From 314c9baefe3b92b73d0a86ca09862ee7293915a7 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Fri, 27 Feb 2026 13:22:10 +0800 Subject: [PATCH] fix: resolve duplicate variable declaration compilation errors - 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 --- VBA_BOMConverter/Modules/M09_BOMExtractor.bas | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas index 08d3cd0..8fc453a 100644 --- a/VBA_BOMConverter/Modules/M09_BOMExtractor.bas +++ b/VBA_BOMConverter/Modules/M09_BOMExtractor.bas @@ -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