subscript out of range error in vbscript

前端 未结 1 1565
逝去的感伤
逝去的感伤 2021-01-21 00:55

Can someone look at the below script and tell me why it\'s throwing this error subscript out of range error in vbscript ..In the text file there are two entries it writes to the

相关标签:
1条回答
  • 2021-01-21 01:52

    If your file contains trailing blank lines, applying Split() may return arrays with less than 2 elements. In that case token(1) should throw a 'subscript out of range' error.

    You should always check, if Split() workes as expected:

    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
    
    0 讨论(0)
提交回复
热议问题