WSCRIPT错误:下标超出范围

时间:2016-09-15 13:20:12

标签: vbscript

我有一个VBScript尝试根据公共字段合并来自两个CSV文件的数据。当我运行我的脚本时,我在第5行char 1上收到错误:

  

下标超出范围。

我尝试根据两者之间的公共字段的值合并的两个文件位于同样放置脚本的文件夹中。

我的代码是:

    'Instatiate FSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the CSV file for reading. The file is in the same folder as the script and named csv_sample.csv.

Wscript.Echo "Path " & objFSO.GetParentFolderName(WScript.ScriptFullName)
'Open the store locations file first
Set brandCSV = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & "SizeGuideLookup_test.csv",1,False)
'Set header status to account for the first line as the column headers.
IsHeader = True
'Initialize the var for the output string.
OutRecord = ""
'Read each line of the file.
Wscript.Echo "Starting Brand File loop"
Do Until brandCSV.AtEndOfStream
    brandLine = brandCSV.ReadLine
    If IsHeader Then
        OutTxt = "PIM Size Type,PIM Identifier,Structure Group,PIM Size Groupd Value Lookup,Size Group To Upload" & vbCrLf
        IsHeader = False
    Else
        'parse brandrecord and get brand id
        brandLineArray=Split(brandLine,";")
        brandBrandId = brandLineArray(0)
        ' loop through Store Location file and get matching data
        foundLocation=false
        Set storeLocCSV = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & "SizeGuideMapping.csv",1,False)
        Do Until storeLocCSV.AtEndOfStream
            outLine=""
            storeLine=storeLocCSV.ReadLine
            storeLineArray=Split(storeLine,";")
            storeBrandId = storeLineArray(0)
            'if the brand IDs match, append the brand data to the end of the store data.
            If brandBrandId = storeBrandId Then
              ' match found - ouptut data (specific fields from store Line + brand line)
              outLine = outLine & brandLineArray(0)
              outLine = outLine & "," & brandLineArray(1)
              outLine = outLine & "," & brandLineArray(2)
                          outLine = outLine & "," & storeLineArray(1)
              outLine = outLine & "," & storeLineArray(1)
              foundLocation=true
              'append created line to end of output text data
              OutTxt = OutTxt & outLine & vbCrLf
            End If
        Loop
        'Close the store location file.
        storeLocCSV.close   
        'if we havent found the data, add empty fields to end of line
        if foundLocation=false Then
            ' no locations for this brand - create brand-only record
            outLine = brandLineArray(0) & ",,," 
                        outLine = outLine & "," & brandLineArray(1)
            outLine = outLine & "," & brandLineArray(2)
                        outLine = outLine & "," & storeLineArray(1)
            outLine = outLine & "," & storeLineArray(1)
            'append created line to end of output text data
            OutTxt = OutTxt & outLine & vbCrLf
        end if
    End If
Loop
'Close the brand file.
brandCSV.Close
'Open the output file for writing.
Set objOutCSV = objFSO.CreateTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & "brandfile.csv",True)
'Write the var OutTxt to the file overwriting existing contents.
objOutCSV.Write OutTxt
'Close the file.
objOutCSV.Close
Set objFSO = Nothing

2 个答案:

答案 0 :(得分:0)

错误发生的行与您提供的(猜测不是全部)的来源不符合,但可能是

WScript.Arguments(0)

导致Subscript out of range错误,因为脚本期望参数WshUnnamedWshNamed个对象)被传递,但似乎没有在0集合对象的索引WshArguments

如果参数确实是文件路径,那么您希望使用wscript.execscript.exe这样的(在命令提示符下); < / p>

cscript.exe /nologo "yourscript.vbs" "C:\some\file\path"

然后

WScript.Echo "Path " & WScript.Arguments(0)

被称为你应该得到(基于这个例子)

C:\some\file\path

有用的链接

答案 1 :(得分:-1)

如果我是对的,你想获得执行脚本的文件夹路径。

为此,您不想使用$('#calendar').fullCalendar({ eventBorderColor: "#de1f1f" }); ,而是使用WScript.Arguments(0)