Solved

Subscript out of range

Posted on 2004-10-14
18
4,916 Views
Last Modified: 2008-02-20
I'm getting this error message:

Microsoft VBScript runtime  error '800a0009'
Subscript out of range: '[number: 2]'
/admin/list.asp, line 113

The script basically prints out the folder and file name of a document that has been downloaded from our intranet site:

    <%
    dim username: username= Request.Querystring("o")
    dim objConn,objRS
    dim strSQL,sConnString
    strSQL="SELECT username, download, datevalue(tracking.date) as datDateDownloaded FROM tracking WHERE username= '" & username & "' order by download, tracking.date"
   
    sConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("database.mdb")
    Set objConn = Server.CreateObject("ADODB.Connection")
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objConn.Open sConnString
    objRS.Open strSQL,objConn,3,3
   
    Response.Write ("<table>")
    Response.Write ("<tr>")
    Response.Write ("<td>Folder</td>")
    Response.Write ("<td>Document</td>")
    Response.Write ("<td>Date</td>")
    Response.Write ("</tr>")

    Dim curFold,Path,Fold,sFolder,sFile
    curFold=""

    Do While not objRS.EOF
    Path=objRS("download")
    arr = split(path, "/")

    *****************************

    this is where the problem appears to be

    *****************************
   
    Fold=arr(0)
    If curFold="" Then
        curFold=Fold
        sFolder=Fold
    ElseIf curFold<>Fold Then
        curFold=Fold
        sFolder=Fold
    Else
        sFolder=""
    End If

    Response.Write ("<tr>")
    Response.Write ("<td>" & sFolder & "</td>")
    Response.Write ("<td>" & arr(1) & ":<br>" & arr(2) & "</td>")
    Response.Write ("<td>" & (objRS("datDateDownloaded")) & "</td>")  
    Response.Write ("</tr>")

    objRS.MoveNext
    Loop
    Response.Write ("</table>")
       
    objRS.Close
    objConn.Close
    Set objRS = Nothing
    Set objConn = Nothing
   
    %>

The site structure is like this:

/download.asp   (the script that records the user download into the database)
/folder1  ( one of many root-level folders )
/folder1/folder2  ( one of many second-level folders )
/folder1/folder2/page.asp  ( where the individual pages sit )

The download from any of those pages is called like this:

<a href="../../download.asp?file=folder1/folder2/document.pdf">Document</a>

I'm sure you'll need some more info to understand the problem - please let me know...

Thanks,
Sean
0
Comment
Question by:seanpowell
  • 9
  • 9
18 Comments
 
LVL 31

Author Comment

by:seanpowell
ID: 12311861
... I "think" the problem is that the number of folders is one less for the pages we've jusr added than for the existing pages that work fine - I assume the script "needs" too see an exact replica of the structure ????
0
 
LVL 19

Expert Comment

by:peh803
ID: 12311879
The error must be occurring on this line:
  Response.Write ("<td>" & arr(1) & ":<br>" & arr(2) & "</td>")

Just before the line, do this:
Dim iCnt
if isArray(arr) then  
  response.write "ubound(arr): "&ubound(arr)&"<BR>"
  response.write "path: "&path&"<BR>"
  for iCnt = 0 to ubound(arr)
    response.write "arr("&i&"): "&arr(i)&"<BR>"
  next
else
  response.write "arr isn't an array!"
end if
response.end
0
 
LVL 19

Expert Comment

by:peh803
ID: 12311885
let me know what the output of the above code is...
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12311889
Yes, I think I've answered my own question... the folder structure was different.

Which begs another new question...
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12311898
Sorry peh803  - didn't see your comment, let me read through it...

Sean
0
 
LVL 19

Accepted Solution

by:
peh803 earned 500 total points
ID: 12311915
no, that's okay
we can keep it here...

Try doing this:

change this line:
Response.Write ("<td>" & arr(1) & ":<br>" & arr(2) & "</td>")

to this:
response.write "<td>"
for i=1 to ubound(arr)
  response.write arr(i) & ":<br>"
next
response.write "</td>"


This should make the code dynamic...
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12311939
Yes - that's the issue all right. If I may....

What currently happens is that I get this:


User Report for Sean Powell

Folder               Document                 Date
==============================
folder1              folder2                     10/14/04
                        mydoc.doc

What I need to happen is this:

Section               Folder               Document                 Date
=========================================
careers              folder1              folder2                     10/14/04
                                                 mydoc.doc

Do you think we could customize the script to work that way?
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12311949
:-)

Missed your comment again - back in a bit after testing it out...
0
 
LVL 19

Expert Comment

by:peh803
ID: 12311975
yes, we can do that.

The first step, I would guess, would be to get the "section" value into your sql statement.  Do you know how to do this?

it'd be something like this:
strSQL="SELECT [section_tablename.section_field_name] AS section, username, download, datevalue(tracking.date) as datDateDownloaded FROM tracking INNER JOIN section_tablename ON tracking.primaryKey = section_tablename.foreignKey WHERE username= '" & username & "' order by download, tracking.date"
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:peh803
ID: 12311976
okay, sounds good to me.. :)
0
 
LVL 19

Expert Comment

by:peh803
ID: 12312002
hm, I guess you're all set :)

Let me know if you want any help getting the section heading in your result page.

regards,
peh803
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12312014
Your last comment appears to do just that - it's fabulous :-)

will keep testing...
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12312063
Just need to get rid of the trailing slash...

I changed this:

response.write arr(i) & ":<br>"

to this:

response.write arr(i) & "/"

so it prints out folder/doc/docname.pdf

but obviously I'm getting:

folder/doc/docname.pdf/

Is it possible to remove that last slash ?
0
 
LVL 19

Expert Comment

by:peh803
ID: 12312097
sure, do something like this:

if i<ubound(arr) then
  response.write arr(i) & "/"
else
  response.write arr(i)
end if

0
 
LVL 31

Author Comment

by:seanpowell
ID: 12312135
Hmm - maybe I wasn't clear :-(

I just wanted to remove the final   /   after the filename, not the filename itself...
0
 
LVL 19

Expert Comment

by:peh803
ID: 12312192
right, doesn't this do that?

Here's the code I'd use:

response.write "<td>"
for i=1 to ubound(arr)
  if i=ubound(arr) then
  '' i is equal to the upper bound of the array, which means that this is the file name;
  '' thus, we don't want to write a slash...
    response.write arr(i)
  else
  '' i is not equal to the upper bound of the array, which means that we're still running
  '' through directory structure---thus, we DO want to write a slash...
    response.write arr(i) & "/"
  end if
next
response.write "</td>"

HTH,
peh803
0
 
LVL 31

Author Comment

by:seanpowell
ID: 12312211
Well now it does :-)

You see pure unadulterated asp code, I see greek (which is not one of my languages)

Thank you so much for your patience, I really appreciate it :-)

Sean
0
 
LVL 19

Expert Comment

by:peh803
ID: 12312230
no problem at all, glad to help :)

You may see "greek", but after a while, you won't see any code at all.

"all I see now is blond, brunette, redhead..."
:) -- potentially misquoted reference from The Matrix, when Cipher is talking to Neo about the Matrix

take care,
peh803
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

17 Experts available now in Live!

Get 1:1 Help Now