Array Problem - Microsoft VBScript runtime error '800a0009'

Posted on 2005-05-08
Last Modified: 2008-02-01
This is the code on a page where I am trying to delete a number or records form a database and images from a file on server.  

The first page displays all the images with a check box beside each image to select it you want to delete the image.  When this page is submitted it goes to a page where the id numbers of each record are taken and stored in an array, when looping through the code to delete the images I get the following error:

(First 3 lines - just to check code)

Upperbound = 1
IDno(0) = 36 Select * From Images WHERE id =36
IDno(1) = 37 Select * From Images WHERE id =37

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '2'

/cp/gallerydelete.asp, line 24

The Code on the page:

dim rs, cn, i, j

idnos=split(idno,", ")      ' stores the values in the arrays                  
response.write ("Upperbound = " & Ubound(idnos))

if not checkcount <1 then

set cn = server.createobject("ADODB.Connection")
cn.provider = application("strProvider") application("strConDB")      

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
for i = 0 to checkcount
response.write("<br>IDno(" & i & ") = " & idnos(i) & "  ")    <<<<<<<< line with error
strSQL="Select *  From Images WHERE id =" & idnos(i)
set rs = cn.execute(strSQL)
objFSO.DeleteFile Server.mapPath("/galleryimages/") & "\" & rs.fields("Imagename"), False
Set objFSO = Nothing
set rs = nothing

sSQL = "DELETE from Images WHERE Id IN(0,0" & Request("chk") & ")"

set cn = nothing

Question by:harris9999
    LVL 46

    Accepted Solution

    1) don't forget that arrays start at 0
    2) to loop through all results, try:

    for i = LBound(idnos) to UBound(idnos)
      'your code

    LVL 46

    Expert Comment

    Now the reason you get your error is as follows--

    First you do this:


    and then later you do this:

    for i = 0 to checkcount
       response.write("<br>IDno(" & i & ") = " & idnos(i) & "  ")    

    By doing so, you are telling the script to move one item more through the array then actually exists, so of course you are going to get a subscript out of range error.

    LVL 3

    Author Comment

    LVL 46

    Expert Comment

    Glad to have helped.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    761 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

    10 Experts available now in Live!

    Get 1:1 Help Now