Vbscript subscript out of range error

Posted on 2012-08-29
Last Modified: 2012-08-30
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
Question by:Aks001
    LVL 12

    Assisted Solution

    Try adding an if statement to handle a null value in len (trim(strinputline))

    Author Comment

    thanks for the prompt response.

    will u be able to tell me with example and the reason of this error?

    Author Comment

    Because I do have the line like

    if len (trim(strinputline)) > 0 then
    LVL 51

    Accepted Solution

    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.


    Author Closing Comment


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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This is an addendum to the following article: Acitve Directory based Outlook Signature ( The script is fine, and works in normal client-server domains…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now