Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><del>Take a look <a href="http://en.allexperts.com/q/Visual-Basic-1048/string-manipulation.htm" rel="nofollow noreferrer">here</a>:</del><br> <strong>Edit:</strong> The referenced source (allexperts.com) has closed, but here's the relevant <a href="https://web.archive.org/web/20090629091145/http://www.allexperts.com:80/ep/1048-18393/Visual-Basic/Robert-Nunemaker.htm" rel="nofollow noreferrer">author</a> comments:</p> <blockquote> <p>There are many algorithms available on the web for sorting. The most versatile and usually the quickest is the <a href="https://en.wikipedia.org/wiki/Quicksort" rel="nofollow noreferrer"><strong>Quicksort algorithm</strong></a>. Below is a function for it. </p> <p>Call it simply by passing an array of values (string or numeric; it doesn't matter) with the <strong>Lower Array Boundary</strong> (usually <code>0</code>) and the <strong>Upper Array Boundary</strong> (i.e. <code>UBound(myArray)</code>.)</p> <p><strong><em>Example</em></strong>: <code>Call QuickSort(myArray, 0, UBound(myArray))</code></p> <p>When it's done, <code>myArray</code> will be sorted and you can do what you want with it.<br> <sub>(Source: <a href="https://web.archive.org/web/20090621095100/http://en.allexperts.com:80/q/Visual-Basic-1048/string-manipulation.htm" rel="nofollow noreferrer">archive.org</a>)</sub></p> </blockquote> <pre><code>Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long) Dim pivot As Variant Dim tmpSwap As Variant Dim tmpLow As Long Dim tmpHi As Long tmpLow = inLow tmpHi = inHi pivot = vArray((inLow + inHi) \ 2) While (tmpLow &lt;= tmpHi) While (vArray(tmpLow) &lt; pivot And tmpLow &lt; inHi) tmpLow = tmpLow + 1 Wend While (pivot &lt; vArray(tmpHi) And tmpHi &gt; inLow) tmpHi = tmpHi - 1 Wend If (tmpLow &lt;= tmpHi) Then tmpSwap = vArray(tmpLow) vArray(tmpLow) = vArray(tmpHi) vArray(tmpHi) = tmpSwap tmpLow = tmpLow + 1 tmpHi = tmpHi - 1 End If Wend If (inLow &lt; tmpHi) Then QuickSort vArray, inLow, tmpHi If (tmpLow &lt; inHi) Then QuickSort vArray, tmpLow, inHi End Sub </code></pre> <p>Note that this only works with <strong>single-dimensional</strong> (aka "normal"?) arrays. (There's a working multi-dimensional arraye QuickSort <a href="https://stackoverflow.com/a/5104206/8112776">here</a>.) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload