ko 中if 和visible 的区别

本文比较了visible和ifbinding两种方式在控制组件动态显示时的区别。ifbinding会改变DOM结构,适用于不需要频繁切换显示状态的情况;而visible则通过CSS实现隐藏,更适合频繁切换。

visible和if binding都可以控制某个组件动态显示与否,

总结一下二者的异同:

与visible binding类似,都可以控制一段内容是否出现在页面中。 

与visible不同的是,if binding是真正的控制Html标签是否出现在DOM中,如果绑定的值为false,则Html标签不会出现在页面中。 

if绑定会修改DOM结构,所以出于性能考虑,不应该频繁修改if的绑定值。(这种情况应该使用visible binding) 

如果与observable或者computed属性绑定,则会产生双向绑定效果。

通俗的解释一下区别就是,当不显示时:


     if 里面的dom内容全部删除
    visible 是使用display:none


运行截图:



隐藏时:




显示时

vba优化运行速度 Sub hz1() 'SHL 汇总 Application.ScreenUpdating = False '刷新 Application.DisplayAlerts = False '警告框 On Error Resume Next Dim i As Long, j As Long, k%, clast%, blast%, dlast% Dim dbook As Workbook, sht As Worksheet, asht As Worksheet, bsht As Worksheet, csht As Worksheet, dsht As Worksheet, tsht As Worksheet Dim qmdz1 As String Dim fso As Object Dim mainFolder As Object Dim subFolder As Object Dim file As Object Dim wb As Workbook Dim ws As Worksheet Dim folderPath As String Dim filePath As String For Each sht In ThisWorkbook.Worksheets sht.Visible = True Next Set csht = ThisWorkbook.Sheets("SHL保管率(全体)") 'Set asht = ThisWorkbook.Sheets("Map") Set esht = ThisWorkbook.Sheets("SHL①平铺") Set fsht = ThisWorkbook.Sheets("SHL②小货架") Set gsht = ThisWorkbook.Sheets("SHL③高层货架") a = csht.Range("E1") '年 b = csht.Range("F1") '月 c = csht.Range("E2") '年 d = csht.Range("F2") '月 f = csht.Range("G1") '日 g = csht.Range("G2") '日 e = csht.Range("B2") '请款方 If a <> "" And b <> "" And c <> "" And d <> "" And f <> "" And g <> "" Then a3 = a & "/" & b & "/" & f & "-" & c & "/" & d & "/" & g '年月日-年月日 nd1 = Val(a) '起始年 nd2 = Val(c) '结束年 nd3 = Val(b) '起始月 nd4 = Val(d) '结束月 nd5 = Val(f) '起始日 nd6 = Val(g) '结束日 edoo = esht.Cells(3, Columns.Count).End(xlToLeft).Column '最后一列 If (nd1 = nd2) And (nd3 = nd4) And (nd3 <> Val(Format(Date, "m"))) Then '非本月 Then For Each sht In ThisWorkbook.Worksheets If sht.Name Like "*" & e & "*" And Not sht.Name Like "*全体*" Then sht.Range(sht.Cells(4, 9), sht.Cells(7, edoo)) = "0" sht.Range(sht.Cells(25, 9), sht.Cells(28, edoo)) = "0" If sht.Name Like "*" & e & "*平铺*" Or sht.Name Like "*" & e & "*高层货架*" Then sht.Range(sht.Cells(4, 9), sht.Cells(8, edoo)) = "0" End If AA = 1 End If Next ElseIf (nd1 = nd2) And (nd3 = nd4) And (nd3 = Val(Format(Date, "m"))) Then For Each sht In ThisWorkbook.Worksheets If sht.Name Like "*" & e & "*" And Not sht.Name Like "*全体*" Then sht.Activate sht.Range(sht.Cells(4, nd5 + 8), sht.Cells(7, nd6 + 8)) = "0" sht.Range(sht.Cells(25, nd5 + 8), sht.Cells(28, nd6 + 8)) = "0" If sht.Name Like "*" & e & "*平铺*" Or sht.Name Like "*" & e & "*高层货架*" Then sht.Range(sht.Cells(4, nd5 + 8), sht.Cells(8, nd6 + 8)) = "0" End If AA = 1 End If Next Else MsgBox "请重新输入年月日!" Exit Sub End If If AA = 1 Then qmdz1 = "\\desktop\1.Draft\" qmdz2 = qmdz1 & nd1 & "年度\" & nd3 & "月\" folderPath = qmdz2 ' qmdz3 = qmdz2 & "PARTS\" ' qmdz4 = qmdz2 & "PRODUCTS\" ' qmdz5 = qmdz2 & "辅材\" esht.Activate For ko = nd5 To nd6 If ko = 1 Then '2025/n/1 If nd3 = 1 Then ny = (nd1 - 1) & "12" & "31" ny1 = nd1 & "0" & nd3 & "01" ElseIf nd3 <> 1 And nd3 <= 10 Then If (nd3 - 1) = 1 Or (nd3 - 1) = 3 Or (nd3 - 1) = 5 Or (nd3 - 1) = 7 Or (nd3 - 1) = 8 Then ny = nd1 & "0" & (nd3 - 1) & "31" ElseIf (nd3 - 1) = 4 Or (nd3 - 1) = 6 Or (nd3 - 1) = 9 Then ny = nd1 & "0" & (nd3 - 1) & "30" ElseIf (nd3 - 1) = 2 Then ny = nd1 & "0" & (nd3 - 1) & "28" End If ny1 = nd1 & "0" & nd3 & "" & "01" ElseIf nd3 > 10 And nd3 <= 12 Then If (nd3 - 1) = 10 Then ny = nd1 & (nd3 - 1) & "31" ElseIf (nd3 - 1) = 11 Then ny = nd1 & (nd3 - 1) & "30" End If ny1 = nd1 & nd3 & "01" End If ElseIf ko <> 1 And ko <= 10 Then ' If nd3 >= 1 And nd3 < 10 Then ny = nd1 & "0" & nd3 & "0" & (ko - 1) ny1 = nd1 & "0" & nd3 & "0" & ko ElseIf nd3 >= 10 And nd3 <= 12 Then ny = nd1 & nd3 & "0" & (ko - 1) ny1 = nd1 & nd3 & "0" & ko End If ElseIf ko > 10 And ko <= 31 Then ' If nd3 >= 1 And nd3 < 10 Then ny = nd1 & "0" & nd3 & (ko - 1) ny1 = nd1 & "0" & nd3 & ko ElseIf nd3 >= 10 And nd3 <= 12 Then ny = nd1 & nd3 & (ko - 1) ny1 = nd1 & nd3 & ko End If End If '所转数据的表头日期 ' nyn = Left(ny, 4) '年 ' nyy = Mid(ny, 5, 2) '月 ' nyr = Right(ny, 2) '日 With esht edoo = .Cells(3, Columns.Count).End(xlToLeft).Column '最后一列 For ho = edoo To 9 Step -1 If Val(.Cells(3, ho)) = ko Then ho1 = ho Exit For End If Next ho End With qmdz3 = qmdz2 Filename = Dir(qmdz3) Do While Filename <> "" Name1 = Filename If Name1 Like "INVENTORY*SONGHAN*" & ny & "*" Then '获取当月的draft gon = Name1 If gon <> "" Then qmdz = qmdz3 & gon Set dbook = Workbooks.Open(qmdz) '打开draft1 For Each sht In dbook.Worksheets If sht.Name Like "INVENTORY*SONGHAN*" & ny & "*" Then sht.Activate sht.AutoFilterMode = False '取消筛选 ro1 = "": ro2 = "": doo = "": dlast = "" With sht dlast1 = .Cells(Rows.Count, 1).End(3).Row 'draft1的最后一行 dlast2 = .Cells(Rows.Count, 3).End(3).Row 'draft1的最后一行 If dlast1 < dlast2 Then dlast = dlast2 Else dlast = dlast1 End If ro1 = 1 ro2 = dlast doo = .Cells(ro1, Columns.Count).End(xlToLeft).Column 'draft最后一列 If (ro1 = "") Or (ro2 = "") Or (doo = "") Then MsgBox "draft表 未抓取到相关行列,请检查!" Exit Sub End If rolk = "": ko1 = "": ko2 = "": ko3 = "": ko4 = "" For koo = 1 To doo If .Cells(ro1, koo) <> "" Then rolk = .Cells(ro1, koo) If rolk = "BG-CODE" Then ko1 = koo ElseIf rolk = "STOCK-DATE" Then ko2 = koo ElseIf rolk = "LOCATION" Then ko3 = koo ElseIf rolk = "RECEIVING-LOCATION" Then '判断成品/部品 ko4 = koo End If End If Next If (ko1 = "") Or (ko2 = "") Or (ko3 = "") Then MsgBox "draft表 未抓取到相关行列,请检查!" Exit Sub End If .Cells(ro1, doo + 1) = "BG" .Cells(ro1, doo + 2) = "LA" .Cells(ro1, doo + 3) = "BG唯一" .Cells(ro1, doo + 4) = "库位数" .Cells(ro1, doo + 5) = "OVER库位数" For k = (ro1 + 1) To dlast If .Cells(k, ko1) <> "" Then .Cells(k, doo + 1) = Right(.Cells(k, ko1), 3) '3字BG If Left(.Cells(k, ko3), 3) = "ZSD" Then '平铺 .Cells(k, doo + 2) = .Cells(k, ko3) ElseIf Left(.Cells(k, ko3), 1) = "E" Or Left(.Cells(k, ko3), 1) = "F" Then '小货架 .Cells(k, doo + 2) = Left(.Cells(k, ko3), 3) ElseIf Left(.Cells(k, ko3), 3) = "ZSA" Then '高层 .Cells(k, doo + 2) = .Cells(k, ko3) End If ElseIf .Cells(k, ko1) = "" And .Cells(i, ko4) Like "*---*" Then If Left(.Cells(k, ko3), 3) = "ZSA" Then '高层 .Cells(k, doo + 1) = "FGS" .Cells(k, doo + 2) = .Cells(k, ko3) End If End If Next Dim overOneYearCount As Long Dim oneYearAgo As Date yt = Val(Left(ny1, 4)) mt = Val(Mid(ny1, 5, 2)) dt = Val(Right(ny1, 2)) gfdg = DateSerial(yt, mt, dt) ' 使用DateSerial函数将年、月、日转换为日期类型 oneYearAgo = CDate(gfdg) - 365 Dim BGDict As Object Dim LADict As Object Dim BGName As String Dim LANumber As String Dim xdf As String xdf = "" For y = 1 To 3 If y = 1 Then xdf = "ZSD" '平铺 Set tsht = esht tst = tsht.Cells(Rows.Count, 1).End(3).Row 'draft1的最后一行 ElseIf y = 2 Then xdf = "E/F" '小货架 Set tsht = fsht ElseIf y = 3 Then xdf = "ZSA" '高层 Set tsht = gsht End If kse = 1 CC: If kse = 1 Then nds = "SHL-P" '部品 to1 = 4 to2 = 6 to3 = 25 to4 = 27 ElseIf kse = 2 Then '成品 nds = "SHL-B" to1 = 7 to2 = to1 to3 = 28 to4 = to3 ElseIf kse = 3 Then '辅材 nds = "---" to1 = 8 to2 = to1 to3 = 0 to4 = 0 Else GoTo DD End If ' 创建字典来存储BG库位信息 Set BGDict = CreateObject("Scripting.Dictionary") Set LADict = CreateObject("Scripting.Dictionary") ' 遍历每一行数据 For i = (ro1 + 1) To dlast If y <> 2 And (.Cells(i, doo + 1) <> "" And .Cells(i, doo + 2) <> "") And (Left(.Cells(i, doo + 2), 3) = xdf) And (.Cells(i, ko4) Like nds & "*") Then '???平铺/小货架/高层+部品/成品/辅材 BGName = .Cells(i, doo + 1).Value LANumber = .Cells(i, doo + 2).Value ' 检查BG是否已在字典中 If Not BGDict.Exists(BGName) Then Set BGDict(BGName) = CreateObject("Scripting.Dictionary") End If '检查料号是否已在该BG的字典中 If Not BGDict(BGName).Exists(LANumber) Then BGDict(BGName)(LANumber) = 1 '不存在,添加到字典并设置初始计数为1 Else BGDict(BGName)(LANumber) = BGDict(BGName)(LANumber) + 1 '存在,则计数加1 End If ' 检查料号是否已在全局料号字典中 If Not LADict.Exists(LANumber) Then Set LADict(LANumber) = CreateObject("Scripting.Dictionary") End If If Not LADict(LANumber).Exists(BGName) Then LADict(LANumber).Add BGName, 1 ' 添加非重复关系 End If ElseIf y = 2 And (.Cells(i, doo + 1) <> "" And .Cells(i, doo + 2) <> "") And (Left(.Cells(i, doo + 2), 1) = "E" Or Left(.Cells(i, doo + 2), 1) = "F") And (.Cells(i, ko4) Like nds & "*") Then '???平铺/小货架/高层+部品/成品/辅材 BGName = .Cells(i, doo + 1).Value LANumber = .Cells(i, doo + 2).Value ' 检查BG是否已在字典中 If Not BGDict.Exists(BGName) Then Set BGDict(BGName) = CreateObject("Scripting.Dictionary") End If '检查料号是否已在该BG的字典中 If Not BGDict(BGName).Exists(LANumber) Then BGDict(BGName)(LANumber) = 1 '不存在,添加到字典并设置初始计数为1 Else BGDict(BGName)(LANumber) = BGDict(BGName)(LANumber) + 1 '存在,则计数加1 End If ' 检查料号是否已在全局料号字典中 If Not LADict.Exists(LANumber) Then Set LADict(LANumber) = CreateObject("Scripting.Dictionary") End If If Not LADict(LANumber).Exists(BGName) Then LADict(LANumber).Add BGName, 1 ' 添加非重复关系 End If End If Next i ' 输出不重复的BG j = ro1 + 1 '从第二行开始 For Each Key In BGDict.Keys .Cells(j, doo + 3).Value = Key j = j + 1 Next Dim idx As Long, tdg As Long tdg = BGDict.Count '按条件筛选出来的BG数量 If tdg = 0 Then GoTo EE For i = ro1 To tdg BGName = .Cells(i + 1, doo + 3).Value If Len(Trim(BGName)) = 0 Then GoTo SkipIteration ' 跳过空名称 Dim tlt As Double, otlt As Double tlt = 0: otlt = 0 For Each Key In BGDict(BGName).Keys If LADict.Exists(Key) Then Dim djf As Long, shk As Long djf = LADict(Key).Count '每个料号对应的BG数 shk = BGDict(BGName)(Key) '每个BG同一个料号的个数 jdh = 0 For m = (ro1 + 1) To dlast hgr1 = Val(Cells(m, ko2).Value) hgr2 = Val(Format(oneYearAgo, "yyyymmdd")) If .Cells(m, doo + 1) = BGName And (.Cells(m, doo + 2) = Key) And (Val(Cells(m, ko2).Value) < Val(Format(oneYearAgo, "yyyymmdd"))) Then jdh = jdh + 1 '每个BG同一个料号 日期超一年的个数 End If Next m hrd = 1 '默认个数1 If djf > 0 And hrd > 0 And shk > 0 Then tlt = tlt + hrd / djf ' 关联BG数量 otlt = otlt + jdh / shk Else MsgBox BGName & " " & Key & "在表中存在异常" & sht.Name Exit Sub End If End If Next .Cells(i + 1, doo + 4).Value = tlt '库位 .Cells(i + 1, doo + 5).Value = otlt '超1年库位 If tlt < otlt Then MsgBox "数据抓取异常,请重新转取!" Exit Sub End If SkipIteration: Next i For X = (ro1 + 1) To (tdg + 1) For k = to1 To to2 '平铺/小货架/高层 If .Cells(X, doo + 3) = tsht.Cells(k, 3) Then tsht.Cells(k, ho1) = tsht.Cells(k, ho1) + .Cells(X, doo + 4) End If Next k For Z = to3 To to4 '超一年 平铺 If .Cells(X, doo + 3) = tsht.Cells(Z, 3) Then tsht.Cells(Z, ho1) = tsht.Cells(Z, ho1) + .Cells(X, doo + 5) End If Next Z Next X .Range(.Cells(ro1 + 1, doo + 3), .Cells(tdg + 1, doo + 5)) = "" EE: Set BGDict = Nothing Set LADict = Nothing kse = kse + 1 GoTo CC DD: Next y End With End If Next dbook.Close '关闭 Exit Do End If End If Filename = Dir Loop '符合日期的提取 Next csht.Activate csht.Range("m1") = "Generate Date:" csht.Range("n1") = Format(Now, "yyyy/mm/dd hh:mm:ss") Call sv End If Else MsgBox "请输入完整的年份月份!" Exit Sub End If Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub
最新发布
12-06
以下vba运行速度太慢,帮我优化以下(具体的程序需求是从一张表的数据经过各种条件得出的结果根据不同的条件填到对应的表中) Sub hz1() 'SHL 汇总 Application.ScreenUpdating = False '刷新 Application.DisplayAlerts = False '警告框 On Error Resume Next Dim i As Long, j As Long, k%, clast%, blast%, dlast% Dim dbook As Workbook, sht As Worksheet, asht As Worksheet, bsht As Worksheet, csht As Worksheet, dsht As Worksheet, tsht As Worksheet Dim qmdz1 As String Dim fso As Object Dim mainFolder As Object Dim subFolder As Object Dim file As Object Dim wb As Workbook Dim ws As Worksheet Dim folderPath As String Dim filePath As String For Each sht In ThisWorkbook.Worksheets sht.Visible = True Next Set csht = ThisWorkbook.Sheets("SHL保管率(全体)") 'Set asht = ThisWorkbook.Sheets("Map") Set esht = ThisWorkbook.Sheets("SHL①平铺") Set fsht = ThisWorkbook.Sheets("SHL②小货架") Set gsht = ThisWorkbook.Sheets("SHL③高层货架") a = csht.Range("E1") '年 b = csht.Range("F1") '月 c = csht.Range("E2") '年 d = csht.Range("F2") '月 f = csht.Range("G1") '日 g = csht.Range("G2") '日 e = csht.Range("B2") '请款方 If a <> "" And b <> "" And c <> "" And d <> "" And f <> "" And g <> "" Then a3 = a & "/" & b & "/" & f & "-" & c & "/" & d & "/" & g '年月日-年月日 nd1 = Val(a) '起始年 nd2 = Val(c) '结束年 nd3 = Val(b) '起始月 nd4 = Val(d) '结束月 nd5 = Val(f) '起始日 nd6 = Val(g) '结束日 edoo = esht.Cells(3, Columns.Count).End(xlToLeft).Column '最后一列 If (nd1 = nd2) And (nd3 = nd4) And (nd3 <> Val(Format(Date, "m"))) Then '非本月 Then For Each sht In ThisWorkbook.Worksheets If sht.Name Like "*" & e & "*" And Not sht.Name Like "*全体*" Then sht.Range(sht.Cells(4, 9), sht.Cells(7, edoo)) = "0" sht.Range(sht.Cells(25, 9), sht.Cells(28, edoo)) = "0" If sht.Name Like "*" & e & "*平铺*" Or sht.Name Like "*" & e & "*高层货架*" Then sht.Range(sht.Cells(4, 9), sht.Cells(8, edoo)) = "0" End If AA = 1 End If Next ElseIf (nd1 = nd2) And (nd3 = nd4) And (nd3 = Val(Format(Date, "m"))) Then For Each sht In ThisWorkbook.Worksheets If sht.Name Like "*" & e & "*" And Not sht.Name Like "*全体*" Then sht.Activate sht.Range(sht.Cells(4, nd5 + 8), sht.Cells(7, nd6 + 8)) = "0" sht.Range(sht.Cells(25, nd5 + 8), sht.Cells(28, nd6 + 8)) = "0" If sht.Name Like "*" & e & "*平铺*" Or sht.Name Like "*" & e & "*高层货架*" Then sht.Range(sht.Cells(4, nd5 + 8), sht.Cells(8, nd6 + 8)) = "0" End If AA = 1 End If Next Else MsgBox "请重新输入年月日!" Exit Sub End If If AA = 1 Then qmdz1 = "\\desktop\1.Draft\" qmdz2 = qmdz1 & nd1 & "年度\" & nd3 & "月\" folderPath = qmdz2 ' qmdz3 = qmdz2 & "PARTS\" ' qmdz4 = qmdz2 & "PRODUCTS\" ' qmdz5 = qmdz2 & "辅材\" esht.Activate For ko = nd5 To nd6 If ko = 1 Then '2025/n/1 If nd3 = 1 Then ny = (nd1 - 1) & "12" & "31" ny1 = nd1 & "0" & nd3 & "01" ElseIf nd3 <> 1 And nd3 <= 10 Then If (nd3 - 1) = 1 Or (nd3 - 1) = 3 Or (nd3 - 1) = 5 Or (nd3 - 1) = 7 Or (nd3 - 1) = 8 Then ny = nd1 & "0" & (nd3 - 1) & "31" ElseIf (nd3 - 1) = 4 Or (nd3 - 1) = 6 Or (nd3 - 1) = 9 Then ny = nd1 & "0" & (nd3 - 1) & "30" ElseIf (nd3 - 1) = 2 Then ny = nd1 & "0" & (nd3 - 1) & "28" End If ny1 = nd1 & "0" & nd3 & "" & "01" ElseIf nd3 > 10 And nd3 <= 12 Then If (nd3 - 1) = 10 Then ny = nd1 & (nd3 - 1) & "31" ElseIf (nd3 - 1) = 11 Then ny = nd1 & (nd3 - 1) & "30" End If ny1 = nd1 & nd3 & "01" End If ElseIf ko <> 1 And ko <= 10 Then ' If nd3 >= 1 And nd3 < 10 Then ny = nd1 & "0" & nd3 & "0" & (ko - 1) ny1 = nd1 & "0" & nd3 & "0" & ko ElseIf nd3 >= 10 And nd3 <= 12 Then ny = nd1 & nd3 & "0" & (ko - 1) ny1 = nd1 & nd3 & "0" & ko End If ElseIf ko > 10 And ko <= 31 Then ' If nd3 >= 1 And nd3 < 10 Then ny = nd1 & "0" & nd3 & (ko - 1) ny1 = nd1 & "0" & nd3 & ko ElseIf nd3 >= 10 And nd3 <= 12 Then ny = nd1 & nd3 & (ko - 1) ny1 = nd1 & nd3 & ko End If End If '所转数据的表头日期 ' nyn = Left(ny, 4) '年 ' nyy = Mid(ny, 5, 2) '月 ' nyr = Right(ny, 2) '日 With esht edoo = .Cells(3, Columns.Count).End(xlToLeft).Column '最后一列 For ho = edoo To 9 Step -1 If Val(.Cells(3, ho)) = ko Then ho1 = ho Exit For End If Next ho End With qmdz3 = qmdz2 Filename = Dir(qmdz3) Do While Filename <> "" Name1 = Filename If Name1 Like "INVENTORY*SONGHAN*" & ny & "*" Then '获取当月的draft gon = Name1 If gon <> "" Then qmdz = qmdz3 & gon Set dbook = Workbooks.Open(qmdz) '打开draft1 For Each sht In dbook.Worksheets If sht.Name Like "INVENTORY*SONGHAN*" & ny & "*" Then sht.Activate sht.AutoFilterMode = False '取消筛选 ro1 = "": ro2 = "": doo = "": dlast = "" With sht dlast1 = .Cells(Rows.Count, 1).End(3).Row 'draft1的最后一行 dlast2 = .Cells(Rows.Count, 3).End(3).Row 'draft1的最后一行 If dlast1 < dlast2 Then dlast = dlast2 Else dlast = dlast1 End If ro1 = 1 ro2 = dlast doo = .Cells(ro1, Columns.Count).End(xlToLeft).Column 'draft最后一列 If (ro1 = "") Or (ro2 = "") Or (doo = "") Then MsgBox "draft表 未抓取到相关行列,请检查!" Exit Sub End If rolk = "": ko1 = "": ko2 = "": ko3 = "": ko4 = "" For koo = 1 To doo If .Cells(ro1, koo) <> "" Then rolk = .Cells(ro1, koo) If rolk = "BG-CODE" Then ko1 = koo ElseIf rolk = "STOCK-DATE" Then ko2 = koo ElseIf rolk = "LOCATION" Then ko3 = koo ElseIf rolk = "RECEIVING-LOCATION" Then '判断成品/部品 ko4 = koo End If End If Next If (ko1 = "") Or (ko2 = "") Or (ko3 = "") Then MsgBox "draft表 未抓取到相关行列,请检查!" Exit Sub End If .Cells(ro1, doo + 1) = "BG" .Cells(ro1, doo + 2) = "LA" .Cells(ro1, doo + 3) = "BG唯一" .Cells(ro1, doo + 4) = "库位数" .Cells(ro1, doo + 5) = "OVER库位数" For k = (ro1 + 1) To dlast If .Cells(k, ko1) <> "" Then .Cells(k, doo + 1) = Right(.Cells(k, ko1), 3) '3字BG If Left(.Cells(k, ko3), 3) = "ZSD" Then '平铺 .Cells(k, doo + 2) = .Cells(k, ko3) ElseIf Left(.Cells(k, ko3), 1) = "E" Or Left(.Cells(k, ko3), 1) = "F" Then '小货架 .Cells(k, doo + 2) = Left(.Cells(k, ko3), 3) ElseIf Left(.Cells(k, ko3), 3) = "ZSA" Then '高层 .Cells(k, doo + 2) = .Cells(k, ko3) End If ElseIf .Cells(k, ko1) = "" And .Cells(i, ko4) Like "*---*" Then If Left(.Cells(k, ko3), 3) = "ZSA" Then '高层 .Cells(k, doo + 1) = "FGS" .Cells(k, doo + 2) = .Cells(k, ko3) End If End If Next Dim overOneYearCount As Long Dim oneYearAgo As Date yt = Val(Left(ny1, 4)) mt = Val(Mid(ny1, 5, 2)) dt = Val(Right(ny1, 2)) gfdg = DateSerial(yt, mt, dt) ' 使用DateSerial函数将年、月、日转换为日期类型 oneYearAgo = CDate(gfdg) - 365 Dim BGDict As Object Dim LADict As Object Dim BGName As String Dim LANumber As String Dim xdf As String xdf = "" For y = 1 To 3 If y = 1 Then xdf = "ZSD" '平铺 Set tsht = esht tst = tsht.Cells(Rows.Count, 1).End(3).Row 'draft1的最后一行 ElseIf y = 2 Then xdf = "E/F" '小货架 Set tsht = fsht ElseIf y = 3 Then xdf = "ZSA" '高层 Set tsht = gsht End If kse = 1 CC: If kse = 1 Then nds = "SHL-P" '部品 to1 = 4 to2 = 6 to3 = 25 to4 = 27 ElseIf kse = 2 Then '成品 nds = "SHL-B" to1 = 7 to2 = to1 to3 = 28 to4 = to3 ElseIf kse = 3 Then '辅材 nds = "---" to1 = 8 to2 = to1 to3 = 0 to4 = 0 Else GoTo DD End If ' 创建字典来存储BG库位信息 Set BGDict = CreateObject("Scripting.Dictionary") Set LADict = CreateObject("Scripting.Dictionary") ' 遍历每一行数据 For i = (ro1 + 1) To dlast If y <> 2 And (.Cells(i, doo + 1) <> "" And .Cells(i, doo + 2) <> "") And (Left(.Cells(i, doo + 2), 3) = xdf) And (.Cells(i, ko4) Like nds & "*") Then '???平铺/小货架/高层+部品/成品/辅材 BGName = .Cells(i, doo + 1).Value LANumber = .Cells(i, doo + 2).Value ' 检查BG是否已在字典中 If Not BGDict.Exists(BGName) Then Set BGDict(BGName) = CreateObject("Scripting.Dictionary") End If '检查料号是否已在该BG的字典中 If Not BGDict(BGName).Exists(LANumber) Then BGDict(BGName)(LANumber) = 1 '不存在,添加到字典并设置初始计数为1 Else BGDict(BGName)(LANumber) = BGDict(BGName)(LANumber) + 1 '存在,则计数加1 End If ' 检查料号是否已在全局料号字典中 If Not LADict.Exists(LANumber) Then Set LADict(LANumber) = CreateObject("Scripting.Dictionary") End If If Not LADict(LANumber).Exists(BGName) Then LADict(LANumber).Add BGName, 1 ' 添加非重复关系 End If ElseIf y = 2 And (.Cells(i, doo + 1) <> "" And .Cells(i, doo + 2) <> "") And (Left(.Cells(i, doo + 2), 1) = "E" Or Left(.Cells(i, doo + 2), 1) = "F") And (.Cells(i, ko4) Like nds & "*") Then '???平铺/小货架/高层+部品/成品/辅材 BGName = .Cells(i, doo + 1).Value LANumber = .Cells(i, doo + 2).Value ' 检查BG是否已在字典中 If Not BGDict.Exists(BGName) Then Set BGDict(BGName) = CreateObject("Scripting.Dictionary") End If '检查料号是否已在该BG的字典中 If Not BGDict(BGName).Exists(LANumber) Then BGDict(BGName)(LANumber) = 1 '不存在,添加到字典并设置初始计数为1 Else BGDict(BGName)(LANumber) = BGDict(BGName)(LANumber) + 1 '存在,则计数加1 End If ' 检查料号是否已在全局料号字典中 If Not LADict.Exists(LANumber) Then Set LADict(LANumber) = CreateObject("Scripting.Dictionary") End If If Not LADict(LANumber).Exists(BGName) Then LADict(LANumber).Add BGName, 1 ' 添加非重复关系 End If End If Next i ' 输出不重复的BG j = ro1 + 1 '从第二行开始 For Each Key In BGDict.Keys .Cells(j, doo + 3).Value = Key j = j + 1 Next Dim idx As Long, tdg As Long tdg = BGDict.Count '按条件筛选出来的BG数量 If tdg = 0 Then GoTo EE For i = ro1 To tdg BGName = .Cells(i + 1, doo + 3).Value If Len(Trim(BGName)) = 0 Then GoTo SkipIteration ' 跳过空名称 Dim tlt As Double, otlt As Double tlt = 0: otlt = 0 For Each Key In BGDict(BGName).Keys If LADict.Exists(Key) Then Dim djf As Long, shk As Long djf = LADict(Key).Count '每个料号对应的BG数 shk = BGDict(BGName)(Key) '每个BG同一个料号的个数 jdh = 0 For m = (ro1 + 1) To dlast hgr1 = Val(Cells(m, ko2).Value) hgr2 = Val(Format(oneYearAgo, "yyyymmdd")) If .Cells(m, doo + 1) = BGName And (.Cells(m, doo + 2) = Key) And (Val(Cells(m, ko2).Value) < Val(Format(oneYearAgo, "yyyymmdd"))) Then jdh = jdh + 1 '每个BG同一个料号 日期超一年的个数 End If Next m hrd = 1 '默认个数1 If djf > 0 And hrd > 0 And shk > 0 Then tlt = tlt + hrd / djf ' 关联BG数量 otlt = otlt + jdh / shk Else MsgBox BGName & " " & Key & "在表中存在异常" & sht.Name Exit Sub End If End If Next .Cells(i + 1, doo + 4).Value = tlt '库位 .Cells(i + 1, doo + 5).Value = otlt '超1年库位 If tlt < otlt Then MsgBox "数据抓取异常,请重新转取!" Exit Sub End If SkipIteration: Next i For X = (ro1 + 1) To (tdg + 1) For k = to1 To to2 '平铺/小货架/高层 If .Cells(X, doo + 3) = tsht.Cells(k, 3) Then tsht.Cells(k, ho1) = tsht.Cells(k, ho1) + .Cells(X, doo + 4) End If Next k For Z = to3 To to4 '超一年 平铺 If .Cells(X, doo + 3) = tsht.Cells(Z, 3) Then tsht.Cells(Z, ho1) = tsht.Cells(Z, ho1) + .Cells(X, doo + 5) End If Next Z Next X .Range(.Cells(ro1 + 1, doo + 3), .Cells(tdg + 1, doo + 5)) = "" EE: Set BGDict = Nothing Set LADict = Nothing kse = kse + 1 GoTo CC DD: Next y End With End If Next dbook.Close '关闭 Exit Do End If End If Filename = Dir Loop '符合日期的提取 Next csht.Activate csht.Range("m1") = "Generate Date:" csht.Range("n1") = Format(Now, "yyyy/mm/dd hh:mm:ss") Call sv End If Else MsgBox "请输入完整的年份月份!" Exit Sub End If Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub
12-06
新insmod实现/* vi: set sw=4 ts=4: */ /* * Mini insmod implementation for busybox * * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi> * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ //config:config INSMOD //config: bool "insmod (22 kb)" //config: default y //config: help //config: insmod is used to load specified modules in the running kernel. //applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET_NOEXEC(insmod, insmod, BB_DIR_SBIN, BB_SUID_DROP, insmod))) //kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y) //kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o //kbuild:endif #include "libbb.h" #include "modutils.h" /* 2.6 style insmod has no options and required filename * (not module name - .ko can't be omitted) */ //usage:#if !ENABLE_MODPROBE_SMALL //usage:#define insmod_trivial_usage //usage: IF_FEATURE_2_4_MODULES("[-fkvqLx] MODULE") //usage: IF_NOT_FEATURE_2_4_MODULES("FILE") //usage: IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...") //usage:#define insmod_full_usage "\n\n" //usage: "Load kernel module" //usage: IF_FEATURE_2_4_MODULES( "\n" //usage: "\n -f Force module to load into the wrong kernel version" //usage: "\n -k Make module autoclean-able" //usage: "\n -v Verbose" //usage: "\n -q Quiet" //usage: "\n -L Lock: prevent simultaneous loads" //usage: IF_FEATURE_INSMOD_LOAD_MAP( //usage: "\n -m Output load map to stdout" //usage: ) //usage: "\n -x Don't export externs" //usage: ) //usage:#endif int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int insmod_main(int argc UNUSED_PARAM, char **argv) { char *filename; int rc; /* Compat note: * 2.6 style insmod has no options and required filename * (not module name - .ko can't be omitted). * 2.4 style insmod can take module name without .o * and performs module search in default directories * or in $MODPATH. */ IF_FEATURE_2_4_MODULES( getopt32(argv, INSMOD_OPTS INSMOD_ARGS); argv += optind - 1; ); filename = *++argv; if (!filename) bb_show_usage(); rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0)); if (rc) bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); return rc; } 原实现/* vi: set sw=4 ts=4: */ /* * Mini insmod implementation for busybox * * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi> * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ //applet:IF_INSMOD(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP)) #include "libbb.h" #include "modutils.h" #include <sys/utsname.h> #ifndef CONFIG_FEATURE_2_4_MODULES #include <sys/mman.h> #include <asm/unistd.h> #include <sys/syscall.h> #endif static char *g_filename = NULL; static int FAST_FUNC check_module_name_match(const char *filename, struct stat *statbuf, void *userdata, int depth) { char *fullname = (char *) userdata; char *tmp; if (fullname[0] == '\0') return FALSE; tmp = bb_get_last_path_component_nostrip(filename); if (strcmp(tmp, fullname) == 0) { /* Stop searching if we find a match */ g_filename = xstrdup(filename); return FALSE; } return TRUE; } static int find_module(char *filename) { char *module_dir, real_module_dir[FILENAME_MAX]; int len, slen, ret = ENOENT, k_version; struct utsname myuname; const char *suffix = ".ko"; struct stat st; /* check the kernel version */ if (uname(&myuname) != 0) return EINVAL; k_version = myuname.release[0] - '0'; if (k_version < 2 || k_version > 9) return EINVAL; if (k_version == 2) { int k_patchlevel = myuname.release[2] - '0'; if (k_patchlevel <= 4) #if ENABLE_FEATURE_2_4_MODULES suffix = ".o"; #else return EINVAL; #endif } len = strlen(filename); slen = strlen(suffix); /* check for suffix and absolute path first */ if ((len < slen + 2) || (strcmp(filename + len - slen, suffix) != 0)) { filename = xasprintf("%s%s", filename, suffix); } else { filename = strdup(filename); if ((stat(filename, &st) == 0) && S_ISREG(st.st_mode)) { g_filename = filename; return 0; } free(filename); return ENOENT; } /* next: scan /lib/modules/<release> */ /* Jump through hoops in case /lib/modules/`uname -r` * is a symlink. We do not want recursive_action to * follow symlinks, but we do want to follow the * /lib/modules/`uname -r` dir, So resolve it ourselves * if it is a link... */ /* ** Orig Sentence is "module_dir = concat_path_file(CONFIG_DEFAULT_MODULES_DIR, myuname.release);" ** Now there is "iplatform" dir in CONFIG_DEFAULT_MODULES_DIR, and some ko files in it, so we just scan ** CONFIG_DEFAULT_MODULES_DIR path. @@ By TengFei, 14/09/02. */ module_dir = strdup(CONFIG_DEFAULT_MODULES_DIR); if (!module_dir) { return ENOMEM; } if (realpath(module_dir, real_module_dir) != NULL) { free(module_dir); module_dir = real_module_dir; } recursive_action(module_dir, ACTION_RECURSE, check_module_name_match, 0, filename, 0); /* Check if we have a complete path */ if (g_filename == NULL) goto done; if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode)) ret = 0; else free(g_filename); done: free(filename); return ret; } /* 2.6 style insmod has no options and required filename * (not module name - .ko can't be omitted) */ //usage:#if !ENABLE_MODPROBE_SMALL //usage:#define insmod_trivial_usage //usage: IF_FEATURE_2_4_MODULES("[OPTIONS] MODULE ") //usage: IF_NOT_FEATURE_2_4_MODULES("FILE ") //usage: "[SYMBOL=VALUE]..." //usage:#define insmod_full_usage "\n\n" //usage: "Load the specified kernel modules into the kernel" //usage: IF_FEATURE_2_4_MODULES( "\n" //usage: "\n -f Force module to load into the wrong kernel version" //usage: "\n -k Make module autoclean-able" //usage: "\n -v Verbose" //usage: "\n -q Quiet" //usage: "\n -L Lock: prevent simultaneous loads" //usage: IF_FEATURE_INSMOD_LOAD_MAP( //usage: "\n -m Output load map to stdout" //usage: ) //usage: "\n -x Don't export externs" //usage: ) //usage:#endif int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int insmod_main(int argc UNUSED_PARAM, char **argv) { char *filename; int rc, opt; /* Compat note: * 2.6 style insmod has no options and required filename * (not module name - .ko can't be omitted). * 2.4 style insmod can take module name without .o * and performs module search in default directories * or in $MODPATH. */ opt = getopt32(argv, INSMOD_OPTS, NULL, NULL); argv += optind - 1; filename = *++argv; if (!filename) bb_show_usage(); rc = find_module(filename); if (rc || (g_filename == NULL)) goto done; rc = bb_init_module(g_filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0)); if (rc && !(opt & INSMOD_OPT_SILENT)) bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); free (g_filename); done: return rc; }
12-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值