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 October 16th, 2007, 05:55 AM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Arrays - subsript out of range

Hi,

I am trying loop through a one column recordset, which has been Select Distinct'ed.

I simply want to assign an operator to an array so I can later loop through another table and count the number of time that operators appears. The number of operators will vary each time so I need to use a dynamic array.

Code:

str_no=CStr(Request("str_no"))
str_name=CStr(Request("str_name"))

DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=DATA_WAREHOUSE;UID=INFOSEC;pwd=password"
objConn.Open

strSQL="SELECT DISTINCT to_number(ltrim(rtrim(op))) op FROM users WHERE str_no='"& CStr(Request("str_no")) & "' order by op"


Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn

i=0
dim myArray()

while not objRS.eof

* myArray(i)=objRS("op")
objRS.Movenext
i=i+1

wend


I am receiving the error "Microsoft VBScript runtime error '800a0009'

Subscript out of range

/chall_by_coll.asp, line 49"

I have put a * by line 49.

Any ideas on where I am going wrong?

Thanks in advance
Ron


 
Old October 16th, 2007, 06:31 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

You can not refer to a recordset in the way you have, you need to assign it to an array using getRows like:

objRS.Open strSQL, objConn
myArray = objRS.getRows()

Have a look on the net about the getRows part of the above code

Wind is your friend
Matt
 
Old October 19th, 2007, 06:16 AM
Authorized User
 
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mat41
 You can not refer to a recordset in the way you have, you need to assign it to an array using getRows like:

objRS.Open strSQL, objConn
myArray = objRS.getRows()

Have a look on the net about the getRows part of the above code

Wind is your friend
Matt
Thanks for the tip Matt.

I managed to use the GetRows thing to get the unique values into an array.

I now need to get a count of how many times the values occur (in the same table).

Is there an easy way of doing this? I could just select the column and order it by "op" which would look something like this:

101
101
101
302
302
603
603 etc etc

I previously thought I would need a list of the unique values (hence the SELECT DISTINCT above) and then loop though a recordset and count the occurances however I am not getting very far..

Is there a better way of achieving this?

I have not bothered to include my pitiful attempts at coding this problem as I was hoping someone could point me in the right direction.

It's not that complicated is it?

Cheers Guys.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Arrays Crippy Ruby 2 March 6th, 2013 05:59 PM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM
Arrays tajin Excel VBA 0 June 20th, 2004 09:07 AM





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