Solved

Subscript out of range

Posted on 2004-10-14
18
4,928 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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