什麼不行?
option explicit
Dim arrScenarios()
Redim arrScenarios(-1)
addToArray arrScenarios, "simple_string_without_spaces"
addToArray arrScenarios, "any string containing spaces"
addToArray arrScenarios, """any string in double quotes"""
addToArray arrScenarios, chr(34) & "yna string in double quotes" & chr(34)
Sub AddToArray(vArray, Item)
Redim Preserve vArray(UBound(vArray)+1)
vArray(UBound(vArray))=Item
End Sub
Dim ii
For ii = 0 To UBound(arrScenarios)
Wscript.Echo "arrScenarios(" & CStr(ii) & ") = " & arrScenarios(ii)
Next
輸出:
==>cscript \VB_scripts\SO\30317733.vbs
arrScenarios(0) = simple_string_without_spaces
arrScenarios(1) = any string containing spaces
arrScenarios(2) = "any string in double quotes"
arrScenarios(3) = "yna string in double quotes"
原來的答覆:
我只能第二個參數是在addToArray
子程序加工哪種方式猜測,但嘗試雙所有內雙引號如下:
addToArray arrScenarios, """Scenarios\BFTB Scenarios\Tutorial.cos"""
或添加前導,以這種方式尾隨的:
addToArray arrScenarios, chr(34) & "Scenarios\BFTB Scenarios\Tutorial.cos" & chr(34)
_When我運行它,它無法找到file._你能澄清一下這意味着Tutorial.cos?你如何「運行它」 - 你沒有顯示試圖打開文件位置的代碼。 – eurotrash