Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4931
  • Last Modified:

Subscript out of range

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
seanpowell
Asked:
seanpowell
  • 9
  • 9
1 Solution
 
seanpowellAuthor Commented:
... 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
 
peh803Commented:
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
 
peh803Commented:
let me know what the output of the above code is...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
seanpowellAuthor Commented:
Yes, I think I've answered my own question... the folder structure was different.

Which begs another new question...
0
 
seanpowellAuthor Commented:
Sorry peh803  - didn't see your comment, let me read through it...

Sean
0
 
peh803Commented:
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
 
seanpowellAuthor Commented:
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
 
seanpowellAuthor Commented:
:-)

Missed your comment again - back in a bit after testing it out...
0
 
peh803Commented:
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
 
peh803Commented:
okay, sounds good to me.. :)
0
 
peh803Commented:
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
 
seanpowellAuthor Commented:
Your last comment appears to do just that - it's fabulous :-)

will keep testing...
0
 
seanpowellAuthor Commented:
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
 
peh803Commented:
sure, do something like this:

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

0
 
seanpowellAuthor Commented:
Hmm - maybe I wasn't clear :-(

I just wanted to remove the final   /   after the filename, not the filename itself...
0
 
peh803Commented:
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
 
seanpowellAuthor Commented:
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
 
peh803Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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