• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

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
  • 3
2 Solutions
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
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.

Aks001Author Commented:

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now