내 코드 23 행에 "Subscript out of range error"가 나타납니다. .csv 파일을 열고 읽으며 마지막 줄의 데이터를 반환하려고합니다. 입력 정보는 다음과 같습니다VBscript는 배열 내에서 배열 내에서 오류가 발생하지만 배열 외부에서는 오류가 발생하지 않습니다.
Control Unit
Date,Time,Seconds,V1,V2,V3,V4,
07/12/2013 ,11:27:21 ,0 ,Closed ,Closed ,Closed ,Closed ,
07/12/2013 ,11:27:22 ,1 ,Closed ,Closed ,Closed ,Closed ,
while 루프의 외부 내가 말할 경우 WScript.Echo = strValues (3) 다음은 내가 루프 내에서 같은 일을하려고하면, 올바른 데이터를 메아리,하지만 난 단순히 strValues (0) 이외의 다른 값에 대한 범위를 벗어난 에러를 얻는다. while 루프가 완료되면 strValues 배열을 검사하면 7 개의 요소 중 하나를 호출 할 수 있기 때문에 이것을 이해할 수 없습니다. 따라서 배열 strValues
Option Explicit
Dim first, secnd
Dim fso, inputFile
Dim strSource, strLine, strValues
Const ForReading = 1
'Create the file system object
Set fso = CreateObject("Scripting.FileSystemObject")
'Initialize a few items
strSource = "C:\Testing\data.csv"
'Open the source file to read it
Set inputFile = fso.OpenTextFile(strSource,ForReading)
'Read the file line by line
Do while not inputFile.AtEndOfStream
strLine = inputFile.ReadLine
'Split the line on the comma into an array
strValues = Split(strLine, ",")
'Check if the dq number matches
first = strValues(0)
'secnd = strValues(3) 'here it tells me its out of range
Loop
WScript.Echo strLine 'once the loop is over it gives me the values just fine
Wscript.Echo strValues(1)
secnd = strValues(3) 'this gives no error
'Close the file
inputFile.Close
'Clean up
Set inputFile = Nothing
Set fso = Nothing
감사
고마워요! 지금은 많은 의미가 있습니다. – thateurokid23
+1, 비록 내가 그 줄을 무시할 때'.SkipLine'이 더 적절하다고 생각할지라도. –