0
我是VBS新手,我試圖從文本文件中收集的一些變量創建一個數組,但作爲一個測試,當我嘗試回顯數組時,第一個變量爲空,而且我有不知道爲什麼,也許有東西在VBS我不知道,我的代碼如下數組中的空白變量VBS
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "filepath"
archivedCSV = "filepath"
xmlFolder = "filepath"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in objFolder.Files
if lcase(objFSO.GetExtensionName(objFile.Name)) = "csv" then
origName = objFile.Name
origPath = objFile.Path
objFile.Name = "temp.txt"
Set objFile = objFSO.OpenTextFile(objStartFolder & "\temp.txt", 1)
Dim callOffNo()
Dim orderNo()
n = 0
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrFields = Split(strLine, ",")
If arrFields(0) <> "List of Call offs" Then
If arrFields(0) <> "Call Off No" Then
If arrFields(2) <> currentOrder Then
currentOrder = arrFields(2)
ReDim orderNo(n)
orderNo(n) = arrFields(2)
n = n + 1
End If
End If
End If
Loop
For Each order in orderNo
MsgBox order
Next
objFile.Close
newName = Replace(origName, objFSO.GetExtensionName(origPath), "")
archivedName = archivedCSV & "\" & origName
tempFile = objStartFolder & "\temp.txt"
objFSO.MoveFile tempFile, archivedName
Exit for
End if
Next
txt文件看起來像這樣
List of Call offs,,,,
Call Off No,Customer,Order Number,Item No,Quantity
12345,COMPANY,1013,1234,1
12345,COMPANY,1013,8652,1
12345,COMPANY,1013,4652,1
12345,COMPANY,1013,7203,1
12345,COMPANY,1013,3365,1
67891,COMPANY,1020,8963,2
67891,COMPANY,1020,1326,2
因此,應該增加兩個變量的array:1013,1020.然而,第一個MsgBox是空白的,第二個說1020
我敢肯定它的東西簡單,我很想念,
在此先感謝
請不要**使用Dim arr()。 * EVER。*它創建一個沒有實際大小的數組,這意味着只是要求麻煩。如果你需要一個動態數組,使用'ReDim arr(-1)'來創建一個空數組,或者(更好地)使用['System.Collections.ArrayList'](http://msdn.microsoft.com/en-us/ library/system.collections.arraylist%28v = vs.110%29.aspx)對象。 –