当您运行例程时,我会将您的FoundItems重置为零......即代替擦除......只有我......但是您可以使用擦除......我只是发现它不可靠......此外...你试图重拨数组的两个维度,你只能重拨最后一个维度...因此而不是
ReDim保留FoundItems(m+1, m+1)'这实际上是不正确的,因为你只有2个维度的第二个值(0&1),但是它必须被转过来,并且ReDim只有第二个维度...
ReDim保留FoundItems(1, m+1)因此您有无限的dims与2个值即FoundItems(0, x)和FoundItems(1, x)...
我已经编辑了下面的代码,因为我看到了它,但我还没有测试它,因为我这里没有任何方便测试它的东西.
- Option Explicit
- Dim FoundItems() As String, intType(0 To 1) As Integer, varData(0 To 1) As Variant
- Dim objSelCol As AcadSelectionSets, objSelSet As AcadSelectionSet, objBlkRef As AcadBlockReference
- Dim varArray1 As Variant, intCount As Integer
- Public Sub PMS_v2()
- Redim FoundItems(1,0) As String
- Set objSelCol = ThisDrawing.SelectionSets
- For Each objSelSet In objSelCol
- If objSelSet.Name = "PMS" Then
- objSelSet.Delete
- Exit For
- End If
- Next
- Set objSelSet = objSelCol.Add("PMS")
- intType(0) = 0: varData(0) = "INSERT"
- intType(1) = 2: varData(1) = "*"
- objSelSet.Select Mode:=acSelectionSetAll, filtertype:=intType, filterdata:=varData
- For Each objBlkRef In objSelSet
- If objBlkRef.HasAttributes Then
- varArray1 = objBlkRef.GetAttributes
- For intCount = LBound(varArray1) To UBound(varArray1)
- Select Case varArray1(intCount).TagString
- Case "STORESNUMBER"
- strStoresNumber = varArray1(intCount).TextString
- IncrimentCount strStoresNumber
- End Select
- Next intCount
- End If
- Next
- 'Now Extract the Information
- 'Extract to Tab Delimited File
- Dim fso, fl, fln, s
- Dim j As Integer
- fln = "M:\PARTS-LIST\PMS.txt"
- Set fso = CreateObject("Scripting.FileSystemObject")
- If fso.FileExists(fln) Then
- fso.DeleteFile fln
- End If
- Set fl = fso.CreateTextFile(fln)
- For j = 1 To UBound(FoundItems, 2)
- s = GetPartInformation(FoundItems(0 , j), FoundItems(1, j))
- fl.WriteLine s
- Next
- fl.Close
- End Sub
- Private Function GetPartInformation(StoresNumber As String, Quantity As String) As String
- Dim objXML As New DOMDocument
- Dim objRoot As IXMLDOMElement
- Dim objLNode As IXMLDOMElement
- Dim s As String
- objXML.Load "M:\PARTS-LIST\partslist.xml"
- Set objRoot = objXML.documentElement
- For Each objLNode In objRoot.childNodes
- If StoresNumber = objLNode.childNodes(0).Text Then
- s = Quantity & vbTab & StoresNumber & vbTab & objLNode.childNodes(1).Text & vbTab & objLNode.childNodes(2).Text & vbTab & objLNode.childNodes(3).Text
- End If
- Next objLNode
- Set objXML = Nothing
- GetPartInformation = s
- End Function
- Private Sub IncrimentCount(StoresNumber As String)
- On Error Resume Next
- Dim i As Integer, m As Integer
- Dim found As Boolean
- found = False
- m = UBound(FoundItems, 2)
- If Err.Number = 9 Then
- m = 0
- Else
- For i = 1 To m
- If FoundItems(0, i) = StoresNumber Then
- found = True
- FoundItems(1, i) = CInt(FoundItems(1, i)) + 1
- End If
- Next
- End If
- If found = False Then
- ReDim Preserve FoundItems(1, m + 1)
- FoundItems(0, m + 1) = StoresNumber
- FoundItems(1, m + 1) = 1
- End If
- End Sub
我希望能行 |