Print Page | Close Window

Subscript out of range

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7959
Printed Date: 01 April 2026 at 1:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Subscript out of range
Posted By: KCWebMonkey
Subject: Subscript out of range
Date Posted: 09 December 2003 at 7:10am

I have a form that updates many records at once, looping through the records. It all works fine execpt for one field which gives the following error:

Microsoft VBScript runtime error '800a0009'
Subscript out of range: '0'
/dcsp/newCati/adminEmployeesFunction.asp, line 60

Line 60 has been highlighted below:

  For i = LBound(arrID_Num) To UBound(arrID_Num)
   Set editConn = Server.CreateObject("ADODB.Connection")
   editStrDbPathAndName = Server.MapPath("db/catiDb.mdb")
   editStrCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & editStrDbPathAndName
   editConn.ConnectionString = editStrCon
   editConn.open
   sqlQuery = "SELECT Users.* FROM Users WHERE ID_Num=" & arrId_Num(i)
   rsEmployees.CursorType = 2
   rsEmployees.LockType = 3
   rsEmployees.Open sqlQuery, editConn
   IF IsNumeric(arrPC_Num(i)) Then
    rsEmployees.Fields("PC_Num") = CLng(arrPC_Num(i))
   End If
   rsEmployees.Fields("First_Name") = arrFirst_Name(i)
   rsEmployees.Fields("Last_Name") = arrLast_Name(i)
   rsEmployees.Fields("Initials") = arrInitials(i)
   rsEmployees.Fields("User_Name") = arrUser_Name(i)
   IF IsNumeric(arrExtension(i)) Then
    rsEmployees.Fields("Extension") = arrExtension(i)
   End If
   rsEmployees.Fields("Supervisor") = arrSupervisor(i)
   rsEmployees.Update
   editConn.Close
   Set editConn = Nothing
  Next

 

If i comment out that line then all the other fields update correctly.




Replies:
Posted By: aalavar
Date Posted: 09 December 2003 at 11:03am

Sounds like a dumb question, but are you sure you set the array to start at 0 for arrUser_Name?

i.e. try doing rsEmployees.Fields("User_Name") = arrUser_Name(i+1)  and see what happens.



Posted By: KCWebMonkey
Date Posted: 09 December 2003 at 11:28am

This is what i use for the array:

Dim arrUser_Name
arrUser_Name = Split (Request.Form("User_Name"), ", ")

If I change the code like you showed, i get the same error, except that the '0' changes to '[number: 1]'



Posted By: aalavar
Date Posted: 09 December 2003 at 1:09pm

Boy, that was a dumb response I got to delete.... Let's try this again.

The only way I can duplicate this error(or come close), is when the field is blank.  Are you sure there is data for all of the user names?

If I try:  

arrUser_Name = Split ("",", ")
Response.write arrUser_Name(0)

I get this error:

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 0]'

 



Posted By: KCWebMonkey
Date Posted: 09 December 2003 at 1:19pm

I am sure that all the fields have data... and i even did this to verify that wasn't the problem:

If arrUser_Name(i) <> "" Then
  rsEmployees.Fields("User_Name") = arrUser_Name(i)
End If

Maybe the problem is that the values in the fields have underscores (_) in them?

 

and...

Quote Boy, that was a dumb response I got to delete.... Let's try this again.

What did you mean by that?



Posted By: KCWebMonkey
Date Posted: 09 December 2003 at 1:34pm

Holy crap..... i am an idiot... after checking on this for about 3 hours....

Come to find out, i had the field on the form named incorrectly

thanks aalavar for your help (unless you were calling me dumb earlier...)



Posted By: pmormr
Date Posted: 09 December 2003 at 2:00pm

it happens to the best of us...



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: aalavar
Date Posted: 09 December 2003 at 6:29pm
Originally posted by KCWebMonkey KCWebMonkey wrote:

Quote Boy, that was a dumb response I got to delete.... Let's try this again.

What did you mean by that?

I responded, but it was dumb, and I corrected myself with the right question.  I wasn't calling you dumb, I was calling myself dumb! (Anyway, I can only delete my own posts, so I couldn't have deleted any other dumb posts )



Posted By: fernan82
Date Posted: 09 December 2003 at 6:55pm
Next time the best way to figure this kind of error out is something like this, just insert a:

Response.Write(UBound(arrUser_Name))

Right before the error, that way you can tell if the array is being populated correctly. If you get the right number then try this:

For i = 0 To UBound(arrUser_Name)   'When you use split the array always start at 0 so no need to call LBound...
    Response.Write(arrUser_Name(i) & "<br>")
Next

That way you can save a lot of time and a big headache :-)


-------------
FeRnAN
http://www.danasoft.com/">


Posted By: KCWebMonkey
Date Posted: 09 December 2003 at 7:18pm
Thanks Fernan, will try to remember that. I don't have too much experience with arrays, and i guess they are the easiest way to update multiple records at once with Access DB's.


Posted By: d80cxq
Date Posted: 18 December 2003 at 3:41am

Hi,

This is a much simpler problem than the one discussed already, sorry if this is obvious but I am new to ASP and hoping someone can help! I have the following code:

dim hover
dim i

hover =Array("15","10","7","6","8","11")

For each I in hover
   Response.Write hover(i)
Next

But I always get the error:   Subscript out of range: '15'

If I change line 1 to
 dim hover()

I get the error:  Type mismatch

Can anyone enlighten me?
Thanks,
Louise



Posted By: KCWebMonkey
Date Posted: 18 December 2003 at 7:32am

This works:

<% Dim i Dim hover hover = Array("15","10","7","6","8","11") For i = 0 To UBound(hover) Response.Write(hover(i) & "
") Next %><% Dim i Dim hover hover = Array("15","10","7","6","8","11") For i = 0 To UBound(hover) Response.Write(hover(i) & "
") Next %><%
Dim i
Dim hover
hover = Array("15","10","7","6","8","11")
For i = 0 To UBound(hover)
 Response.Write(hover(i) & "<br>")
Next
%>



Posted By: d80cxq
Date Posted: 18 December 2003 at 9:09am

That worked for me as well - thanks a lot!

I had tried all those elements (Ubound, dim hover, dim hover()) etc but just never got the right combination.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net