vbscript中的下标超出范围错误
有人能看一下下面的脚本并告诉我为什么它在vbscript中抛出这个错误下标超出范围错误..在文本文件中有两个条目它正确地写入了文件,但是在退出循环时它抛出了一个错误,所以它从不调用另一个函数..我想它尝试运行3次,但只有2个条目在文本文件中vbscript中的下标超出范围错误,vbscript,Vbscript,有人能看一下下面的脚本并告诉我为什么它在vbscript中抛出这个错误下标超出范围错误..在文本文件中有两个条目它正确地写入了文件,但是在退出循环时它抛出了一个错误,所以它从不调用另一个函数..我想它尝试运行3次,但只有2个条目在文本文件中 The text file is in this format Format.css Shared Design.css Shared Dim strInputPath1 Dim txsInput1,txsOutput Dim FSO
The text file is in this format
Format.css Shared
Design.css Shared
Dim strInputPath1
Dim txsInput1,txsOutput
Dim FSO
Dim Filename
Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = "C:\txt3.txt"
Set txsOutput = FSO.CreateTextFile(strOutputPath)
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
Set f = FSO.OpenTextFile("C:\Users\spadmin\Desktop\Main\combination.txt")
Do Until f.AtEndOfStream
tokens = Split(Trim(re.Replace(f.ReadLine, " ")))
extension = Split(tokens(0),".")
strInputPath1 = "C:\inetpub\wwwroot\Test\files\" & tokens(1) & "\" & extension(1) & "\" & tokens(0)
Set txsInput1 = FSO.OpenTextFile(strInputPath1, 1)
WScript.Echo strInputPath1
txsOutput.Writeline txsInput1.ReadAll
Loop
WScript.Echo "Calling"
txsInput1.Close
txsOutput.Close
f.Close
Call CreateCSSFile()
''''''''''''''''''''''''''''''''''''
' Merge Css Files
''''''''''''''''''''''''''''''''''''
Sub CreateCSSFile()
WScript.Echo "Called"
Dim FilenameCSS
Dim strInputPathCSS
Dim txsInputCSS,txsOutputCSS
Dim FSOCSS
Set FSOCSS = CreateObject("Scripting.FileSystemObject")
strOutputPathCSS = "C:\txt4.txt"
Set txsOutputCSS = FSOCSS.CreateTextFile(strOutputPath)
Set re = New RegExp
re.Pattern = "\s+"
re.Global = True
Set fCSS = FSOCSS.OpenTextFile("C:\Users\spadmin\Desktop\TestingTheWebService\combination.txt")
Do Until fCSS.AtEndOfStream
tokensCSS = Split(Trim(re.Replace(fCSS.ReadLine, " ")))
extensionCSS = Split(tokensCSS(0),".")
strInputPathCSS = "C:\inetpub\wwwroot\EpsShared\c\" & tokensCSS(1) & "\" & extensionCSS(1) & "\" & tokensCSS(0)
Set txsInputCSS = FSOCSS.OpenTextFile(strInputPathCSS, 1)
txsOutputCSS.Writeline txsInputCSS.ReadAll
Loop
fCSS.Close
txsInputCSS.Close
txsOutputCSS.Close
Set FSOCSS = Nothing
End Sub
如果文件包含尾随的空行,则应用Split()可能返回少于2个元素的数组。在这种情况下,
token(1)
应该抛出“下标超出范围”错误
如果Split()按预期工作,则应始终检查:
tokens = Split(Trim(re.Replace(f.ReadLine, " ")))
If 1 = UBound(tokens) Then
extension = Split(tokens(0),".")
If 1 = UBound(extension) Then
strInputPath1 = "..." & tokens(1) & "..."
Else
... parse error ...
End If
Else
... parse error or just trailing blank lines? ...
End If
这很有效。你回答得很快,上一次你也帮了我。非常感谢你。根据实际需求,你还可以通过添加n-1个分隔符来确保始终至少有n个标记,例如:
Split(str&.“,”)
将str
拆分为3个或更多标记。这一个呢?设置WshShell=CreateObject(“WScript.Shell”)defaultprn=WshShell.regrad(“HKEY\U CURRENT\U USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device”)arrPrnStr=Split(defaultprn,”),fullPrinterString=arrPrnStr(0)arrFullPrnStr=Split(fullPrinterString,“\”),shortPrinterName=arrFullPrnStr(Ubound(arrFullPrnStr))defPrinteri.InnerHTML=shortPrinterName defPrinteri.title=fullPrinterString