
Help On sorting arrays
I dont know how to sort my arrays<BR>lets say you have a set of arrays called:<BR>arrCustomer, arrAddress, arrCity, arrPhone<BR><BR>how would you sort the arrCustomer array alphebetically.<BR><BR>note that when sorting, the arrAddress, arrCity, arrPhone has to be moved from its original location<BR><BR>Thanking you in advance<BR>Jeremy

RE: Help On sorting arrays
Short answer: Don't do it.<BR><BR>If you possibly can, sort the arrays in the database before you every get them into array form.<BR><BR>Longer answer: It's a pain in the rear to sort parallel arrays...very slow. You'd be a *lot* better off using an array *of* arrays.<BR><BR>That is, each element of the "outer" array contains an "inner" array which consists of all the parallel elements.<BR><BR>If this question is being asked so that you can let the user request a particular sort of a table in the browser, then may I direct you to http://www.ClearviewDesign.com/NEWBIE and the *two* different demos of sorting tables that I have there. One done using serverside sorting (all ASP) and the other done with clientside JS coding. Incidentally, the latter uses the "native" SORT command (well, function) of JS to do the sort. And I useta da!a *single* array of *objects*. Quite similar to the array of arrays idea.<BR><BR>Come to think of it, doing a sort of an array of objects in VBScript would be the better way to go! Oh, duh! Why didn't I think of that before!<BR><BR>Anyway, *can* you do this in the DB? If not, can you consider converting to a single array of objects (or array of arrays)?<BR><BR>If you really can't then ask again. Doing the parallel arrays isn't *hard*...it's just real slow.<BR>

RE: Help On sorting arrays
I can not do it in a data base, and i do not know how to make arrays of arrays? please help

RE: Help On sorting arrays
I have this so far as my script but it doesn't work for some reason<BR><BR><BR>for m = 0 to ubound(customer)1<BR>for n = 0 to m<BR>if customer(n)>customer(n+1) then<BR>tempCustomer=customer(n+1)<BR>tempUser=use r(n+1)<BR>tempPass=pass(n+1)<BR>tempAddress=addres s(n+1)<BR>tempCity=city(n+1)<BR>tempProvince=provi nce(n+1)<BR>tempPostal=postal(n+1)<BR>tempPhone=ph one(n+1)<BR>tempFax=fax(n+1)<BR>tempEmail=Email(n+ 1)<BR><BR>customer(n+1)=customer(n)<BR>user(n+1)=u ser(n)<BR>pass(n+1)=pass(n)<BR>address(n+1)=addres s(n)<BR>city(n+1)=city(n)<BR>province(n+1)=provinc e(n)<BR>postal(n+1)=postal(n)<BR>phone(n+1)=phone( n)<BR>fax(n+1)=fax(n)<BR>Email(n+1)=Email(n)<BR>cu stomer(n)=tempCustomer<BR>user(n)=tempUser<BR>pass (n)=tempPass<BR>address(n)=tempAddress<BR>city(n)= tempCity<BR>province(n)=tempProvince<BR>postal(n)= tempPostal<BR>phone(n)=tempPhone<BR>fax(n)=tempFax <BR>Email(n)=tempEmail<BR><BR>end if<BR>next<BR>next<BR>

RE: Help On sorting arrays
Your basic loops are wrong! <BR>You are doing:<BR><BR>for m = 0 to ubound(customer)1<BR>for n = 0 to m<BR><BR>You *need* to do:<BR><BR>for m = ubound(customer)1 To 0 Step 1<BR>for n = 0 to m<BR><BR>If you would have done a little Response.Writeing of what elements you were swapping, you would have seen it immediately.<BR><BR>On the other issue:<BR><BR>To convert this to an array of arrays, instead of doing:<BR><BR>Dim user(10),pass(10),city(10) ' or however you did the dims...<BR>user(0) = "bob"<BR>pass(0) = "1xxy32"<BR>city(0) = "bismark"<BR>etc.<BR><BR>You do this:<BR><BR>Dim rows(10)<BR>row(0) = Array("bob","1xxy32","bismark")<BR><BR>And now, instead of sorting by comparing<BR><BR>If user(n) > user(n+1) Then<BR> swap user<BR> swap pass<BR> swap city<BR>End If<BR><BR>You simply do<BR><BR>If rows(n)(0) > rows(n+1)(0) Then<BR> swap rows<BR>End If<BR><BR>Do you get that? It *does* meant that you have to remember the order you put things into the inner array, but the performance gain is considerable.<BR><BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

