Vbscript subscript out of range error

I have one vbscript(.vbs file) as below. The purpose of it is to compare 2 text file. Here we have declared 2 arrays. while running it im getting error subscript out of range (800A0009)
Error on line. computerindex = computerindex + 1 and in the next line we are doing a trim.

plz advise wht might be the error and solution.

 Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim AryComputer(5000,3) set Shell = WScript.CreateObject("WScript.Shell") set wshNetwork = WScript.CreateObject("WScript. Network") set objStdOut = wscript.stdout set FileSysObj = CreateObject("Scripting. FileSystemObject")

set FSOComputerList = FileSysobj.Opentextfile("D:\USI.Data\ComputersDump.txt",ForReading,False,-1) ComputerIndex=0 dummy=FSOComputerList.readline wscript.echo dummy Do Until FSOComputerList.AtEndOfStream StrInputLine=FSOComputerList.ReadLine if len (trim(strinputline)) > 0 then ComputerIndex = ComputerIndex + 1 AryComputer(ComputerIndex,1) = Trim(Ucase(Left(StrInputLine,20))) AryComputer(ComputerIndex,2) = Trim(Mid(StrinputLine,20)) AryComputer(ComputerIndex,3) = 0 end if Loop FSOComputerList.close
Who is Participating?
Bill PrewCommented:
You are getting the error because there are more than 5000 lines in your inpot file, so that ComputerIndex is hitting 5001, which is outside the allowed dimension of the array.

Try displaying each line as you read it in perhaps, or checking the input file for lines you are not expecting.

Try adding an if statement to handle a null value in len (trim(strinputline))
Aks001Author Commented:
thanks for the prompt response.

will u be able to tell me with example and the reason of this error?
Aks001Author Commented:
Because I do have the line like

if len (trim(strinputline)) > 0 then
Aks001Author Commented:

After changing the array size value and handling the null value its running now. I will report If I get any error.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.