Originally Posted by
Coolmo
I want to populate a Combobox with every layer in the drawing but I'd like for them to be in alphabetical order. Is there a quick way to do this? Populating it is easy but it appears to pop them into the combobox in the order that they appear..... in the AutoCAD database? Is there ANY way to alphabetize a list? Any help is appreciated.
try this
or this
Code:
Public Sub Alphabetize(StringArray() As String)
Dim loopOuter As Integer
Dim loopInner As Integer
Dim i As Integer
For loopOuter = UBound(StringArray) To _
LBound(StringArray) Step -1
For loopInner = 0 To loopOuter - 1
If UCase(StringArray(loopInner)) > _
UCase(StringArray(loopInner + 1)) Then
Swap StringArray(loopInner), _
StringArray(loopInner + 1)
End If
Next loopInner
Next loopOuter
End Sub
Private Sub Swap(a As String, b As String)
Dim c As String: c = a: a = b: b = c
End Sub
or this?
Code:
Private Function QSort(strList() As String, lLbound As Long, lUbound As Long)
'Classic QSort function - Modified to *not* be case sensitive (added all "lcase"
functions)
Dim sTemp As String
Dim sBuffer As String
Dim lCurLow As Long
Dim lCurHigh As Long
Dim lCurMid As Long
lCurLow = lLbound 'Start current low and high at actual low/high
lCurHigh = lUbound
If lUbound <= lLbound Then Exit Function
lCurMid = (lLbound + lUbound) \ 2 'Find the approx midpoint of the array
sTemp = LCase(strList(lCurMid))
'Pick as a starting point (we are making an assumption that
'the data *might* be in semi-sorted order already!)
Do While (lCurLow <= lCurHigh)
Do While LCase(strList(lCurLow)) < sTemp
lCurLow = lCurLow + 1
If lCurLow = lUbound Then Exit Do
Loop
Do While sTemp < LCase(strList(lCurHigh))
lCurHigh = lCurHigh - 1
If lCurHigh = lLbound Then Exit Do
Loop
If (lCurLow <= lCurHigh) Then 'if low is <= high then swap
sBuffer = strList(lCurLow)
strList(lCurLow) = strList(lCurHigh)
strList(lCurHigh) = sBuffer
lCurLow = lCurLow + 1 'CurLow++
lCurHigh = lCurHigh - 1 'CurLow--
End If
Loop
If lLbound < lCurHigh Then 'Recurse if necessary
QSort strList(), lLbound, lCurHigh
End If
If lCurLow < lUbound Then 'Recurse if necessary
QSort strList(), lCurLow, lUbound
End If
End Function
one more ...
Code:
'------------------------------------
'Add all layer names to an array
'Return the sorted array
'------------------------------------
Public Function SortLayers() As String()
Dim i As Integer
Dim oLayers As AcadLayers, oLayer As AcadLayer
Set oLayers = ThisDrawing.Layers
ReDim strLayers(0 To oLayers.Count - 1) As String
i = 0
For Each oLayer In oLayers
strLayers(i) = oLayer.Name
i = i + 1
Next oLayer
SortLayers = MergeSort (strLayers)
End Function
'----------------------------------
'Add layers to a combo box named CboLayers
'----------------------------------
Private Sub UserForm_Activate()
Dim strLayers() As String
Dim i As Integer
strLayers = SortLayers()
For i = LBound(strLayers) To UBound(strLayers)
CboLayers.AddItem strLayers(i)
Next i
End Sub
hope one of those helps