Multidimensional Array Sorting using QuickSort isn

Results 1 to 2 of 2

Thread: Multidimensional Array Sorting using QuickSort isn

  1. #1
    Join Date
    Dec 1969

    Default Multidimensional Array Sorting using QuickSort isn

    The code snippet on the following URL is giving me a headache.<BR><BR><BR><BR><BR>I am sure your code works fine in a typical implementation of it, but I am somewhat of a moron when it comes to VBScript. I have more experience in JScript so please forgive me if this is coded weird... Here is my code process with some snippets of my code...<BR><BR>1. Open a delimited text file.<BR>2. Move through the file placing each line in a multidimensional array:<BR><BR>Do While Not tsLinks.AtEndOfStream<BR> ReDim Preserve aryLinks(iCount)<BR> aryLinks(iCount) = Split(tsLinks.ReadLine, "&#124&#124")<BR><BR> iCount = iCount + 1<BR>Loop<BR><BR>3. Call the Quicksort subroutine:<BR><BR> Call QuickSort(aryLinks, LBound(aryLinks), UBound(aryLinks), 1)<BR><BR><BR>Now here is where the issue comes in. I am getting this error:<BR><BR> Subscript out of range: &#039;Ubound&#039;<BR><BR>On this line:<BR><BR> Redim pivot (Ubound(vec,2))<BR><BR>I have no clue why it would fail on this line? When I loop through my array to verify that the values are in the array and that it is dimensioned correctly it works fine.<BR><BR>Here is a sample line from the text file...<BR><BR> 0 &#124&#124 ASP Message Board &#124&#124 &#124&#124 Description of ASP Message Board.

  2. #2
    Join Date
    Dec 1969

    Default The person who wrote that...

    ...has never been active here.<BR><BR>In other words, when you write "I am sure your code ..." you are not talking to anybody who wrote that code. In fact, I&#039;ve never seen a post from him in the past 2 years, since that article was written.<BR><BR>And, on top of that, he completely ignored what is "standard practice" in VBScript for 2D arrays.<BR><BR>************<BR><BR>HOWEVER...<BR>< BR>You&#039;ve been tripped up by your knowledge of JS! <BR><BR>Your code did *NOT* create a 2D array! It created an ARRAY OF ARRAYS. Yes, the same way you would create a PSEUDO-2D array in JS code!<BR><BR>And when you create an array of arrays in VBS, you should refer to the elements the same way you do in JS!<BR><BR>That is, if you do this:<BR>&nbsp; &nbsp; aryLinks(iCount) = Split(tsLinks.ReadLine, "&#124&#124")<BR><BR>Then you refer to a given cell in the array as<BR>&nbsp; &nbsp; aryLinks( row )( colummn ) <BR>!!!<BR><BR>So *now* you are *really* sorting a ONE-DIMENSIONAL array! It&#039;s just that, when you go to compare to rows, instead of comparing the entire row you compare the relevant column within the row.<BR><BR>Probably exactly the same way you did it in JS code! Just using (row)(column) instead of [row][column] !!!<BR><BR>No, do *NOT* change your code! Please! Instead, go find how to sort a 1D array in VBS and adapt that code.<BR><BR>Why? Because it will be a heluva lot more efficient!<BR><BR>Sorting a VBS 2D array is HORRIBLY SLOW, even using quicksort. That&#039;s because, to swap a pair of rows, you have to do a FOR loop to swap each separate column within the rows.<BR><BR>But when you sort an array-of-arrays, you can do it the same way you did in JS: swap the single array elements and the entire rows are swapped. Presto.<BR><BR>Hokay? <BR><BR>Can I ask a silly question? If you know JS, why are you writing this in VBS? If you wrote it in JS, you could use JS&#039;s builtin Array.sort to do it for you.<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