Sorting combo boxes ?

Discussion in 'AutoCAD' started by News, Mar 3, 2004.

  1. News

    News Guest

    Hello all,
    Here is some code I am using to populate a combo box with all the layers in
    a drawing:

    Dim entry As AcadLayer

    For Each entry In ThisDrawing.Layers
    cmbLayers.AddItem entry.Name
    Next

    Is there any way to sort this list alphabetically ?
    Thanks.
     
    News, Mar 3, 2004
    #1
  2. News

    News Guest

    thanks for the help - this is what i ended up doing.

    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) > arrLayers(intTeller + 1) Then
    varTemp = arrLayers(intTeller + 1)
    arrLayers(intTeller + 1) = arrLayers(intTeller)
    arrLayers(intTeller) = varTemp
    End If
    Next intTeller
    cmbLayers.AddItem arrLayers(intRuns)
    Next intRuns
     
    News, Mar 4, 2004
    #2
  3. News

    News Guest

    sorry - i had a problem with duplicates and numbers so i changed the code to
    this:

    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) > 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
     
    News, Mar 4, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.