Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Dimming an array
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GhorZonia
New Member

Finland
60 Posts

Posted - 29 July 2001 :  17:44:45  Show Profile  Visit GhorZonia's Homepage
I have a table which contains two columns: ID and username. I need to create an 1 dimensional array which contains the usernames so that Array(ID) gives the corresponding username. So when I response.write eg. Array(5) it will write the username of the member with the ID 5.

I have done it like this. I use GetRows because I have heard it is a lot faster than using movenexts and stuff like that.


SQL = "SELECT ID, Username FROM MEMBERS"
Set RS = Conn.Execute(SQL)

Dim GetRowsArray
GetRowsArray = RS.GetRows

Dim Array(55)

For rowcounter=0 To UBound(GetRowsArray,2)
ID = GetRowsArray(0,rowcounter)
Username = GetRowsArray(1,rowcounter)
Array(ID) = Username
Next

RS.Close
Set RS = Nothing


This works fine, but my problem is the Dim Array(55) line. I have to enter 55 manually as I know there are 55 members in the database. But I don't know how to dim it dynamically (so that I don't have to enter the number of members manually after each update).

I have tried this but it says something like error: integer expected.


num = UBound(GetRowsArray,2)
Dim Array(num)


Any suggestions?

Doug G
Support Moderator

USA
6493 Posts

Posted - 29 July 2001 :  23:02:04  Show Profile
Why don't you just use the existing array you got from GetRows instead of making a new array? It's already dimensioned properly. Make a copy of it if you need to. I use the GetRows array all the time.

The UBound method should work for you if you want to make a new array, maybe you have a typo on the page.

======
Doug G
======
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 30 July 2001 :  01:26:18  Show Profile
If you move the following script from Default.asp to inc_top.asp then you can use the varable Users for the number of members.



'START Count script
set rs1 = Server.CreateObject("ADODB.Recordset")

'## Forum_SQL
strSql = "SELECT " & strTablePrefix & "TOTALS.P_COUNT, " & strTablePrefix & "TOTALS.T_COUNT, " & strTablePrefix & "TOTALS.U_COUNT "
strSql = strSql & " FROM " & strTablePrefix & "TOTALS"

rs1.open strSql, my_Conn

Users = rs1("U_COUNT")
Topics = rs1("T_COUNT")
Posts = rs1("P_COUNT")

rs1.Close
set rs1 = nothing

'End Count SCRIPT




Share A Square at forumSquare


gauravbhabu

There is only one miracle...That is LIFE!
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 30 July 2001 :  01:37:36  Show Profile
Read this


If you request more rows than are available, then GetRows returns only the number of available rows. You can use the UBound function to determine how many rows GetRows actually retrieved, because the array is sized to fit the number of returned rows. For example, if you returned the results into a Variant called varA, you could use the following code to determine how many rows were actually returned:

numReturned = UBound(varA,2) + 1
You need to use "+ 1" because the first row returned is in the 0 element of the array. The number of rows that you can retrieve is constrained by the amount of available memory. You shouldn't use GetRows to retrieve an entire table into an array if it is large.

This is what you seem to be doing. Doug is right. You do not need the second Array.


Share A Square at forumSquare


gauravbhabu

There is only one miracle...That is LIFE!

Edited by - gauravbhabu on 30 July 2001 01:39:30
Go to Top of Page

GhorZonia
New Member

Finland
60 Posts

Posted - 30 July 2001 :  04:52:53  Show Profile  Visit GhorZonia's Homepage
You have to excuse me, I'm still a ASP newbie so I don't always know what I'm doing or why I do it like that

quote:
Why don't you just use the existing array you got from GetRows instead of making a new array?


Umm... I'm not sure what you mean. Could you explain a bit?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.33 seconds. Powered By: Snitz Forums 2000 Version 3.4.07