这是代码:
'creates the msxml object
Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
Dim retVal
'load the xml data of the script
retVal=xmlDoc.load(argFilePath)
Dim fso, folder, sFolder
Dim xmlDataPath, curNode
'get input folder
Set curNode=xmlDoc.selectSingleNode("//ScriptXmlData/inputFilePath")
Dim inputFolder, outputFolder, hotLoc
inputFolder=CSTR(curNode.text)
'location of jdf files
sFolder=inputFolder
'creating file getting object
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(sFolder)
Dim amount, fName, arrC, i
i=0
'loop for getting amounts
For each folderIdx In folder.files
If fso.GetExtensionName(folderIdx.Name) = "jdf" Then
'increase array size
Redim arrC(i)
'get folder name
fName=folderIdx.Name
'get file path
xmlDataPath = sFolder+"\"+fName
'load the xml data of the script
retVal = jdfDoc.load(xmlDataPath)
'get amount
Set curNode = jdfDoc.selectSingleNode("//jdf:JDF/jdf:ResourceLinkPool/jdf:ComponentLink")
amount = curNode.getAttribute("Amount")
'Create array that holds amount
arrC(i)=amount
i=i+1
End If
Next
wscript.echo arrC(0)
wscript.echo arrC(1)
wscript.echo arrC(2)
我们的问题是一旦 arrC 退出循环,它的一些值就会丢失。例如,在循环内部,我们的数组是:
arrC(0)=100
arrC(1)=150
arrC(2)=200
一旦它离开循环,就像在代码末尾的测试中一样,它的值是:
arrC(0)=""
arrC(1)=""
arrC(2)=200
有人可以解释一下吗?
谢谢!