Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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 January 12th, 2009, 08:30 AM
Authorized User
 
Join Date: Nov 2005
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
Default Those ARRAYS are making me crazy

Hi,

I am not really used to program dynamically Arrays, so that´s why I finally will post my question here.

I have a DB with some data and want to add thos data to an array. I found an example using array, the code is
Code:
Dim a, b
Dim h
 
 a = Array("Denmark", "Germany", "Sweden", "Norway", "France", "Italy", "Iceland", "Belgium", "Greenland", "Japan")
 b = Array(1490, 1007, 64, 1938, 1550, 1890, 721, 554, 450, 1450) 
 
 h = Array(1225, 1299, 687, 1571, 153, 1581, 1148, 772, 1295, 414)
 Dim objGraph
 Set objGraph = New PureAspGraph
 objGraph.setTitle("Demonstration 3")
 Call objGraph.setYAxesTitle("Countries")
 Call objGraph.setXAxesTitle("Hits per day")
 
 Call objGraph.setData(a, b)
 Call objGraph.addData(h)
 
 Call objGraph.addLabel("Data 1")
 Call objGraph.addLabel("Data 2") 
 Call objGraph.addLabel("Data 3")
 Call objGraph.addLabel("Data 4")
 Call objGraph.addLabel("Data 5")
 
 Call objGraph.setType(0) 
 Call objGraph.setBarWidth(6)
 Call objGraph.print()
Now I want to see if I can fill these arrays with other data


How can I do this. I thought of just using something like or something like it
Code:
a="Array(")
DO WHILE NOT RS.EOF
  a=a&rs("data")
  Rs.MoveNext
 LOOP 
a=a&")""
...
 Call objGraph.setData(a, b )
 Call objGraph.addData(h)
But it doesn´t work. I know it is simple, but my brain is still in the "I hate mondays" position.....


ny help is welcome!!!!

Thx
 
Old January 12th, 2009, 02:21 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi,

Are you creating this array for the same reason as in your code example? Are you going to create a graph?

Here's some simple code to create an array and populate it.

SQL = "Select Column1 FROM Table1;"
Set oRS = oConn.Execute(SQL)
i = 0
Dim TheArray()
Do While Not oRS.EOF
ReDim preserve TheArray(i)
TheArray(i) = oRS("Column1")
Response.Write TheArray(i) & "<br/>"
i = i + 1

oRS.MoveNext
Loop
 
Old January 13th, 2009, 04:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It would help *A LOT* if you would show us the page where you are getting that PureAspGraph from.

Possibly there is another method you could use that would make all this a *LOT* easier.

But to emulate *exactly* what is in that sample code, you'd need something like this:
Code:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...your connection string..."

Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT a, b, h FROM someTable ORDER BY someOrder"
RS.Open SQL, conn, 3 ' 3 is "adOpenStatic"...
recCount = RS.RecordCount ' must open static to get valid recordCount
maxRec = recCount - 1 ' because arrays are numbered from zero

Dim a(), b(), h()
ReDim a(maxRec), b(maxRec), h(maxRec)

For r = 0 To maxRec
   a(r) = RS("a")
   b(r) = RS("b")
   h(r) = RS("h")
   RS.MoveNext
Next
RS.Close

... and now your three arrays are ready for use ...
You could use ReDim Preserve, as RStelma suggested, but it's a real performance hog and should be avoided when you can. Using the static cursor allows us to avoid it.

But if you give us the URL to PureAspGraph, we might see a better way.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Am I crazy to think I can do this? williamlove Visual Basic 2008 Essentials 1 December 19th, 2008 10:27 PM
Almost crazy trevo4f BOOK: Beginning ASP 3.0 2 May 15th, 2008 11:22 AM
SQL Crazy Query... devendar SQL Server 2005 4 July 19th, 2007 12:51 AM
Crazy Thing happening Kenny Alligood Access VBA 10 February 17th, 2004 12:26 PM





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