Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2006, 02:55 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Array Bounds

I'm pulling a 1-dimensional RecordSet into an array. I then call a For Next loop by doing iArr = 0 to UBound(arrShipUserIDs). However, I consistently get Subscript out of bounds errors and don't know why. I only use iArr to reference indeces within the array within the loop. That is why I don't know what's wrong.

Here's my code:
If Not rsShipAddresses.EOF Then arrShipUserIDs = rsShipAddresses.GetRows : iShipCount = 0
iArr = 0
If LBound(arrShipUserIDs) >= 0 Then
    For iArr = 0 to (UBound(arrShipUserIDs) - 1)
        If arrShipUserIDs(iArr) = 0 Then
            iShipCount = iShipCount + 1
        End If
    Next
    If iShipCount = 0 Then
        iCounter = iCounter - 1
    End If
End If

I had to include the (UBound(arrShipUserIDs) - 1) to get it to stop erroring out. I even wrote out the UBound with Response.Write and for the specific SQL query it is pulling the UBounds results in 0. Could this be the problem?

Specifically it errors on "If arrShipUserIDs(iArr) = 0 Then" only if the UBound(arrShipUserIDs) - 1) isn't in place.

The results on the query are null and I've tried performing Is Nothing checks on arrShipUserIDs(0) but they have resulted in Subscript out of bounds as well.

Any help you can provide is appreciated. If you need anymore details just ask.

Thanks.

 
Old September 27th, 2006, 03:00 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What happens if you do this:

For iArr = 0 to UBound(arrShipUserIDs)
   Response.Write(arrShipUserIDs(iArr))
Next

Dose it cause an error?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 27th, 2006, 03:04 PM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. I've tried that. It still produces the same error.

 
Old September 27th, 2006, 03:11 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Have you tried

For iArr = LBound(arrShipUserIDs) to UBound(arrShipUserIDs)
Next

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 28th, 2006, 07:21 AM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, sir, I have.

 
Old September 28th, 2006, 07:45 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What do you mean by this:

Write and for the specific SQL query it is pulling the UBounds results in 0. Could this be the problem?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old September 28th, 2006, 07:58 AM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I went into Enterprise Manager and manually executed the same SQL query I was with rsShipAddresses and no results were returned. I also did a Response.Write on the UBound of the array in question and it wrote out zero.

So I'm wondering if it would be the null recordset that could be causing the problem.

 
Old September 28th, 2006, 08:28 AM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just did a Response.Write(rsAddresses.RecordCount) and it results in -1. I can take a gander that this is another meaning "nothing" but what other implications does it have?

 
Old September 28th, 2006, 08:35 AM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm officially confused. I just manually executed the query that fills rsShipAddresses with different user's values and I got three records back. But then I asked that user to refresh the page he was on / I was editing and the RecordCount still wrote out to -1.

 
Old September 28th, 2006, 09:01 AM
Authorized User
 
Join Date: Feb 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. Instead of trying to mess with arrays I simply sucked the information I needed from the recordset. Thanks man!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Index was outside the bounds of the array ECPcenter ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2008 04:55 AM
Chapter 4 - SQL Error "Out of Bounds" scottt40 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 7th, 2007 10:56 AM
Index was outside the bounds of the array dba123 Reporting Services 0 March 6th, 2006 11:25 AM
index outside bounds of array error? barmanvarn BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 February 17th, 2005 03:25 PM
System.Index out of Bounds chiraagb ADO.NET 3 June 10th, 2004 12:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.