Subscript out of range error

I'm having trouble tracking down why this error message is popping up.  I'm probably doing something simple and stupid but I've been stairing at it too long.  Below is the code and the results I get from it.

Sub subBuildNameArray(intMonth, intYear)

      Dim intDaysInMonth, arrBirth_Names(), d, r
      
      intDaysInMonth = funcDaysInMonth(intMonth, intYear)
      
      ReDim arrBirth_Names(intDaysInMonth, 20)
      Response.Write(UBound(arrBirth_Names) & "==" & UBound(arrBirth_Names, 2) & "<br>")
      
      For d = 0 To intDaysInMonth - 1
            sqlBirth_Day = "SELECT Name FROM tbl_OCB_Employee_Dates WHERE Birth_Month = " & intMonth &_
                  " And Birth_Day = " & d + 1
            rsBirth_Day.Open sqlBirth_Day, conn
            r = 0
            Do Until rsBirth_Day.EOF
                  Response.Write(d & "--" & r & "<br>")
                  If d < UBound(arrBirth_Names) Then
                        arrBirth_Names(d, r) = rsBirth_Day.Fields("Name")
                  Else
                        Response.Write("Out of range.<br>")
                  End If
                  Response.Write(rsBirth_Day.Fields("Name") & "<br>")
                  rsBirth_Day.MoveNext
                  r = r + 1
            Loop
            ReDim Preserve arrBirth_Names(intDaysInMonth, r)
            rsBirth_Day.Close
      Next
      
      For d = 0 To intDaysInMonth - 1
            Response.Write(Ubound(arrBirth_Names, 2))
            For r = 0 To UBound(arrBirth_Names, 2)
                  Response.Write(arrBirth_Names(d, r) & "<br>")
            Next
      Next
End Sub

subBuildNameArray 11, 2004

Set rsBirth_Day = Nothing
%>

Here is the output.

30==20
0--0
John Smith
1--0
Ron Davids
3--0
Scott Adams
4--0
Rob Fritz
5--0
Max Howard
6--0
Jeana Regal
8--0
Alex Alvero
10--0
Heidi Chalbers
15--0
Mike Krenzy
15--1

Microsoft VBScript runtime error '800a0009'

Subscript out of range: 'd'

/BillingWebDevl/Resources/NewBirthday.asp, line 115
nataSofColsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peh803Commented:
instead of this:

Response.Write(arrBirth_Names(d, r) & "<br>")


You probably want this:

Response.Write(arrBirth_Names(r,d) & "<br>")

Hope this helps!

peh803
0
nataSofColsAuthor Commented:
I'm sorry, I wasn't specific enough.  I pulled this code from a large set, so the line number is not accurate.  The line that is causing the problem is: arrBirth_Names(d, r) = rsBirth_Day.Fields("Name")
0
peh803Commented:
Okay, let me back up a bit.. What are you trying to do here?  I ask because I've reviewed your code further and I'm not sure my solution will help you out because you're doing some unconventional things with arrays, loops, etc.

Typically, users will loop through arrays like this:

for i=0 to ubound(arr,2)
  for o=0 to ubound(arr,1)
    response.write arr(o,i)&"<BR>"
  next
next

Notice how the second dimension of the array is typically the outer-most loop (corresponding to the number of "rows" in a 2d array), and the first dimension is the inner-most loop (corresponding to the number of "columns" in a 2d array).  You seem to be doing it a bit differently, which may be why you're having trouble.  Generally, I think of 2d arrays like this:

0,0   1,0   2,0
0,1   1,1   2,1
0,2   1,2   2,2
0,3   1,3   2,3
0,4   1,4   2,4
0,5   1,5   2,5
0,6   1,6   2,6

So, the array above contains 7 columns (0-->6) and 3 rows (0-->2), and ubound(aboveArray,1) = 2, and ubound(aboveArray,2)=6.  Indeed, if you fetch a recordset's contents into an array, this is the kind of structure you find.  

Does this clear things up at all?
Thanks,
peh803
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

nataSofColsAuthor Commented:
OK, I'm not sure how well that would apply to my situation.  Basically, I have a db table that contains a name, a birth month, and a birth day.  The purpose of all of this is to build a calendar with the appropriate names on the appropriate days.  In this section of code, I'm going through the db table, pulling all names from the particular month and day and then incrementing the day.  The reason for the inner loop is for the case where there are multiple people with the same birth day, so the second loop is not always being used.  This is the reason I'm using a do loop instead of a for loop.  Thanks for working with me on this.
0
peh803Commented:
small world, eh?
0
peh803Commented:
:-)
0
peh803Commented:
actually, fyi, I've gotta run to an 11:00 meeting (which I'm late to, obviously), so if you could bear with me for a bit, that'd be great...I'll get to it asap!

Thanks,
peh803
0
peh803Commented:
you shouldn't need to mess around with arrays to accomplish this; please take a look at the following code, which will loop through your recordset / table structure and display all names of people with birthdays, grouped by date.  I can continue to help further if you have any other questions.

Thank you,
peh803

<%
Dim rs
set rs = server.CreateObject("adodb.recordset")
Dim sLastBDay
sSQL = "SELECT * FROM tbl_OCB_Employee_Dates WHERE birthmonth = '" & month(date()) & "' ORDER BY Birthday"
rs.open sSQL, connection, 1, 3, 1

Response.Write "Here are the birthdays for the month of <b>" & monthName(month(date())) & "</b>:<BR>"
sLastBDay = ""
do while not rs.EOF
  if sLastBDay <> rs("birthday") then
    Response.Write "<B><u>"&rs("birthday")&"</u></B><BR>"
  end if
  Response.Write "Person: "&rs("name")&"<BR>"
  Response.Write "Birthday: "&rs("birthday")&"<BR>"
  sLastBDay = rs("birthday")
  rs.MoveNext
loop
rs.close
set rs = nothing
%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.