<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Listbox - sorting alphabetically? in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066517#M52908</link>
    <description>Most listboxes don't have very many entries in them.  For lists of under 1000 items a Bubble Sort is recommended.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Wayne Ivory&lt;BR /&gt;
IT Analyst Programmer&lt;BR /&gt;
Wespine Industries Pty Ltd</description>
    <pubDate>Fri, 25 Jun 2004 02:39:38 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2004-06-25T02:39:38Z</dc:date>
    <item>
      <title>Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066513#M52904</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
Simple question, I've populated a listbox with layer names but they are in no certain order. I thought that the listbox has a sorted property but it wont let me do&lt;BR /&gt;
&lt;BR /&gt;
Listbox1.sorted=true&lt;BR /&gt;
&lt;BR /&gt;
Any help appreciated&lt;BR /&gt;
&lt;BR /&gt;
Al</description>
      <pubDate>Thu, 24 Jun 2004 14:17:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066513#M52904</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-24T14:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066514#M52905</link>
      <description>I'm not aware of any sort property for listboxes.  I think you'd have to
sort them first.  I haven't done it, but if you have them in an array, I've
seen a few sorting functions on the net, then just pass it to the listbox
with the List property.

HTH

"Pienpeas" &lt;NOSPAM&gt; wrote in message
news:26404003.1088086651697.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; Hi,
&amp;gt;
&amp;gt; Simple question, I've populated a listbox with layer names but they are in
no certain order. I thought that the listbox has a sorted property but it
wont let me do
&amp;gt;
&amp;gt; Listbox1.sorted=true
&amp;gt;
&amp;gt; Any help appreciated
&amp;gt;
&amp;gt; Al&lt;/NOSPAM&gt;</description>
      <pubDate>Thu, 24 Jun 2004 14:48:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066514#M52905</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-24T14:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066515#M52906</link>
      <description>VBA ListBox in ACAD does not do sorting for you. You have do it yourself:
put all layers' name in an string array; choose one of your favorite sorting
algrithm and write your sorting code; sort the array, and then popualte the
listbox/combobox.

Actaully, you do not have to write your onw sorting code, there are a lot
ready to use sorting algrithms on the net. You can google some VB/VBA
related news group for "sorting". Here is one example of what I have found:

Public Sub ShellSort(ByRef A() As Variant, _
ByVal Lb As Long, ByVal Ub As Long)
Dim n As Long, h As Long
Dim i As Long, j As Long
Dim t As Variant
'
' ***** If you are using this routine to sort string data and you want
' it to be case insensitive (ie "cat" comes before "Dog") then you
' must place the line "Option Compare Text" in the (general)
' (declarations) section of the Form or Module in which this routine
' is declared
' *******************************
'
' We allow the user to send his own start and end positions to
' this routine in case he wants to sort only part of the array
' (which is a common requirement) so we must first check and
' adjust those parameters in case he has given us silly numbers!
If Ub &amp;gt; UBound(A) Then Ub = UBound(A)
If Lb &amp;lt; LBound(A) Then Lb = LBound(A)
If Lb &amp;gt;= Ub Then Exit Sub
'
' now sort array (from element lb to element ub)
' first calculate the largest increment
n = Ub - Lb + 1
h = 1
If n &amp;gt; 13 Then
  Do While h &amp;lt; n
    h = 3 * h + 1
  Loop
  h = h \ 3
  If h &amp;gt; (n * 0.8) Then h = h \ 3
End If
' repeatedly do an insertion sort using
' values of h from its initial value down
' to a value of 1
Do While h &amp;gt; 0
  For i = Lb + h To Ub
    t = A(i)
    For j = i - h To Lb Step -h
      If A(j) &amp;lt;= t Then Exit For
      A(j + h) = A(j)
    Next j
    A(j + h) = t
  Next i
  h = h \ 3
Loop
End Sub


"Pienpeas" &lt;NOSPAM&gt; wrote in message
news:26404003.1088086651697.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; Hi,
&amp;gt;
&amp;gt; Simple question, I've populated a listbox with layer names but they are in
no certain order. I thought that the listbox has a sorted property but it
wont let me do
&amp;gt;
&amp;gt; Listbox1.sorted=true
&amp;gt;
&amp;gt; Any help appreciated
&amp;gt;
&amp;gt; Al&lt;/NOSPAM&gt;</description>
      <pubDate>Thu, 24 Jun 2004 14:53:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066515#M52906</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-24T14:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066516#M52907</link>
      <description>The VB version of the listbox has a Sort property.
The VBA version does not.

"Pienpeas" &lt;NOSPAM&gt; wrote in message
news:26404003.1088086651697.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; Hi,
&amp;gt;
&amp;gt; Simple question, I've populated a listbox with layer names but they are in
no certain order. I thought that the listbox has a sorted property but it
wont let me do
&amp;gt;
&amp;gt; Listbox1.sorted=true
&amp;gt;
&amp;gt; Any help appreciated
&amp;gt;
&amp;gt; Al&lt;/NOSPAM&gt;</description>
      <pubDate>Fri, 25 Jun 2004 01:34:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066516#M52907</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-25T01:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066517#M52908</link>
      <description>Most listboxes don't have very many entries in them.  For lists of under 1000 items a Bubble Sort is recommended.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
Wayne Ivory&lt;BR /&gt;
IT Analyst Programmer&lt;BR /&gt;
Wespine Industries Pty Ltd</description>
      <pubDate>Fri, 25 Jun 2004 02:39:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066517#M52908</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-25T02:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066518#M52909</link>
      <description>Thanks guys, its obviously not as simple as i thought!</description>
      <pubDate>Fri, 25 Jun 2004 08:30:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066518#M52909</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-25T08:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Listbox - sorting alphabetically?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066519#M52910</link>
      <description>I ended up using a combobox for my list of layers, too much hassle w/a
listbox.

    Dim intTeller As Integer
    Dim intRuns As Integer
    Dim varTemp As Variant

    Dim entry As AcadLayer

    Dim arrLayers() As Variant
    Dim iCount As Integer

    For Each entry In ThisDrawing.Layers
        ReDim Preserve arrLayers(iCount)
        arrLayers(iCount) = entry.Name
        iCount = iCount + 1
    Next

    For intRuns = 0 To UBound(arrLayers()) - 1
        For intTeller = 0 To UBound(arrLayers()) - 1
            If arrLayers(intTeller) &amp;gt; arrLayers(intTeller + 1) Then
                varTemp = arrLayers(intTeller + 1)
                arrLayers(intTeller + 1) = arrLayers(intTeller)
                arrLayers(intTeller) = varTemp
            End If
        Next intTeller
    Next intRuns

    For intRuns = 0 To UBound(arrLayers())
        cmbLayers.AddItem arrLayers(intRuns)
    Next intRuns

"Pienpeas" &lt;NOSPAM&gt; wrote in message
news:26404003.1088086651697.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; Hi,
&amp;gt;
&amp;gt; Simple question, I've populated a listbox with layer names but they are in
no certain order. I thought that the listbox has a sorted property but it
wont let me do
&amp;gt;
&amp;gt; Listbox1.sorted=true
&amp;gt;
&amp;gt; Any help appreciated
&amp;gt;
&amp;gt; Al&lt;/NOSPAM&gt;</description>
      <pubDate>Wed, 30 Jun 2004 17:16:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/listbox-sorting-alphabetically/m-p/1066519#M52910</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-06-30T17:16:05Z</dc:date>
    </item>
  </channel>
</rss>

