Multi-dimension array sorting

Results 1 to 2 of 2

Thread: Multi-dimension array sorting

  1. #1
    Christiaan Guest

    Default Multi-dimension array sorting

    I&#039m working on a script to sort a multi-dimensional (by default: 2 dimensions) array of strings. Is there a good script that allows sorting of 1 &#039column&#039 in such an array? I can&#039t find a good example anywhere.....<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Multi-dimension array sorting

    If at all possible, avoid sorting a multidimensional array in VBScript.<BR><BR>Reason: When it comes time to swap "rows" in the array, you end up having to do<BR><BR>For column = 0 To UBound( array, 1 )<BR>temp = array( column, fromRow )<BR>array( column, fromRow ) = array( column, toRow )<BR>array( column, toRow ) = temp<BR>Next<BR><BR>Can you say "performance hog!"<BR><BR>If, instead, you use an array *OF* arrays, where each element of the "outer" array contains a complete inner array, then you can sort by simply swapping elements in the outer array.<BR><BR>And if you want to be able to select *which* column the outer array will be sorted on, the basic code is unaffected. Instead of doing a comparsion such as<BR> If array(column,fromRow) &#060; array(column,toRow) Then ...<BR>you simply do<BR> If array(fromRow)(column) &#060; array(toRow)(column) Then ...<BR><BR>In other words, by simplifying your life you&#039ll also speed up your processing, so what have you got to lose?<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