Re-sorting an array?

T

Travis Pupkin

Hi,

Can anyone point me to a good online tutorial (preferably for slow
learners) about advanced handling of arrays, like re-sorting the data,
etc.?

Thanks.
 
G

Gérard Leclercq

dim a (5)
a(0)="zero"
a(1)="one"
a(2)="two"
a(3)="tree"
a(4)="four"
a(5)="five"

for x = 0 to 10
for xx = 0 to 9
If a(xx) > a(xx+1) then
tmp = a(xx+1)
a(xx+1) = a(xx)
a(xx)=tmp
Next xx
Next x

For x = 0 to 5
print a(x)
Next x
 
G

Gérard Leclercq

Ooops

dim a (5)
a(0)="zero"
a(1)="one"
a(2)="two"
a(3)="tree"
a(4)="four"
a(5)="five"

for x = 0 to Ubound(x) or 5
for xx = 0 to Ubound(x-1) or 4
If a(xx) > a(xx+1) then
tmp = a(xx+1)
a(xx+1) = a(xx)
a(xx)=tmp
Next xx
Next x

For x = 0 to 5
print a(x)
Next x
 
B

Bob Barrows [MVP]

Travis said:
Hi,

Can anyone point me to a good online tutorial (preferably for slow
learners) about advanced handling of arrays, like re-sorting the data,
etc.?

Thanks.
http://support.microsoft.com/?kbid=169617

Contains VB code, but it should be easily converted to vbscript by removing
the datatypes from the Dim statements and eliminating the timing code.

Bob Barrows
 
L

larrybud2002

Thanks for the links. I'll try to figure out the examples.

Or you may want to look into disassociated record sets. Then you can
populate the data and let ADO do the sorting.
 
T

Travis Pupkin

Or you may want to look into disassociated record sets. Then you can
populate the data and let ADO do the sorting.

Well, let me tell you what I'm doing. I thought maybe arrays were the
best way to handle it, but, as usual, I could be wrong.

I'm pulling the contents of a table into a page. I need to display the
data in three different sections:

1. The newest rows, sorted by time stamp
2. "Featured" rows, sorted by Name
3. All rows, sorted by Name

Rather than running three different recordsets with slightly different
SQL statements, I thought maybe with an array -- which I'm just learning
about and the sorting methods have been a little confusing -- I could do
just one recordset of all rows and filter and sort it as needed without
having to keep hitting the database (which is the way I've always done
things, and is simple from my p.o.v., but I'm trying to broaden myself
this time around and conserve resources).

Am I on the right track, or would some other method suit me better, like
disassociated record sets (which I had never heard of until now).
 
L

larrybud2002

Or you may want to look into disassociated record sets. Then you
can
Well, let me tell you what I'm doing. I thought maybe arrays were the
best way to handle it, but, as usual, I could be wrong.

I'm pulling the contents of a table into a page. I need to display the
data in three different sections:

1. The newest rows, sorted by time stamp
2. "Featured" rows, sorted by Name
3. All rows, sorted by Name

Rather than running three different recordsets with slightly different
SQL statements, I thought maybe with an array -- which I'm just learning
about and the sorting methods have been a little confusing -- I could do
just one recordset of all rows and filter and sort it as needed without
having to keep hitting the database (which is the way I've always done
things, and is simple from my p.o.v., but I'm trying to broaden myself
this time around and conserve resources).

Am I on the right track, or would some other method suit me better, like
disassociated record sets (which I had never heard of until now).

While I applaud the attempt at learning something new, IMO doing 3
different queries is the best way to do this.

But what a disassociated recordset is is basically a recordset that is
no longer connected to the database. So you could load the data into a
table, then you could resort serverside using ADO on the same data
without making another call to the database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top