You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

sorting items in a ComboBox   Loring Tupper Mar 19, 2003
Re: sorting items in a ComboBox   Neil Clemmons Mar 19, 2003
Re: sorting items in a ComboBox   Loring Tupper Mar 19, 2003
Re: sorting items in a ComboBox   Neil Clemmons Mar 20, 2003
Re: sorting items in a ComboBox   Kirk Kuykendall Mar 20, 2003
Re: sorting items in a ComboBox   Loring Tupper Mar 21, 2003
Re: sorting items in a ComboBox   Loring Tupper Mar 21, 2003
Re: sorting items in a ComboBox   Kirk Kuykendall Mar 21, 2003
Re: sorting items in a ComboBox   Loring Tupper Mar 21, 2003
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject sorting items in a ComboBox 
Author Loring Tupper 
Date Mar 19, 2003 
Message I was looking for the "sorted" property for the ComboBox tool and could not find it, I assume that this property is not available in ArcGIS 8.1.2 VB Macro developement environment. If that is the case how can I get the list in my ComboBox sorted? Initially I am reading an ascii text file and loading it to the ComboBox list via AddItem. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Neil Clemmons 
Date Mar 19, 2003 
Message The combobox control in the VBA environment does not expose a Sorted property like the one in regular VB. You will need to write a routine to sort the data before you add it to the control. Many times, you can use the Windows API to get around these differences, but I think this is one of the times you can't. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Loring Tupper 
Date Mar 19, 2003 
Message Thanks Neil,
I kinda figured that the property wasn't available, thanks for the verification. Any hints on how to sort the info coming in from an ascii file before I load it to the ComboBox list? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Neil Clemmons 
Date Mar 20, 2003 
Message You can find plenty of sort routines on the net. The most efficient is QuickSort, unless the data set is small, in which case something like BubbleSort is probably best. Most sort routines start with the data set loaded into an array, so that is probably your first step -- loading an array with the ascii data. There are many VB sites on the net. If you don't know of any, go to a search engine such as Google and search. Bookmark the ones you like. Many of these sites have extensive resources, such as sample code, solutions to common tasks, helpful hints, etc. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Kirk Kuykendall 
Date Mar 20, 2003 
Message Here's code that adds items and retains alphabetic order.

kkeywords iuicomboboxcontrol 
 
Option Explicit
Sub Test()
    AddItem "zebra", UIComboBoxControl1
    AddItem "banana", UIComboBoxControl1
    AddItem "dog", UIComboBoxControl1
    AddItem "apple", UIComboBoxControl1
    AddItem "cat", UIComboBoxControl1
End Sub

Sub AddItem(sItem As String, cmbBox As IUIComboBoxControl)
    ' adds item retaining alphabetic order
    Dim l As Long
    For l = 0 To cmbBox.ItemCount - 1
        Select Case StrComp(cmbBox.Item(l), sItem, vbTextCompare)
        Case 0: Exit Sub ' already in the combobox
        Case 1
            cmbBox.AddItem sItem, l
            Exit Sub
        End Select
    Next l
    cmbBox.AddItem sItem
End Sub
 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Loring Tupper 
Date Mar 21, 2003 
Message Hi Kirk,
first, thanks for the code, it looks really promising but I am having a little problem implimenting it. Below is the code I am using, the AddItem sub is exactly the same as you sent me and the UserForm_Activate sub is where I'm reading the ascii file that contains my school names I want to load to the ComboBox. the name of the ComboBox is cmbSchName and when I try to run this code I get the following error message:

Run-time error '13':
Type mismatch

and the line "AddItem NextLine, cmbSchName" is hilited by the debugger.
Any idea what I've done wrong?
 
 
Sub AddItem(sItem As String, cmbBox As IUIComboBoxControl)
    ' adds item retaining alphabetic order
    Dim l As Long
    For l = 0 To cmbBox.ItemCount - 1
        Select Case StrComp(cmbBox.Item(l), sItem, vbTextCompare)
        Case 0: Exit Sub ' already in the combobox
        Case 1
            cmbBox.AddItem sItem, l
            Exit Sub
        End Select
    Next l
    cmbBox.AddItem sItem
End Sub

Private Sub UserForm_Activate()
    optAM.Value = True
    optPM.Value = False
    optPublic.Value = True
    optSeperate.Value = False
    
    'Set school name combobox selection list
    Dim schFile As String
    Dim NextLine As String
   
    schFile = "school_names.txt"
   
    Open schFile For Input As #1
   
    Do Until EOF(1)
        Line Input #1, NextLine
        AddItem NextLine, cmbSchName
    Loop
    Close 1
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Loring Tupper 
Date Mar 21, 2003 
Message Hello again,
sorry but I just realized the code you sent me was for a UIComboBoxControl for the ArcMap interface, not a ComboBox control for a VB form created in the ArcMap VB macro developement environment. Any ideas on how to modify the code so it would work on a VB ComboBox control? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Kirk Kuykendall 
Date Mar 21, 2003 
Message try this instead 
 
Option Explicit
Private Sub UserForm_Initialize()
    AddItem "zebra", Me.ComboBox1
    AddItem "banana", Me.ComboBox1
    AddItem "dog", Me.ComboBox1
    AddItem "apple", Me.ComboBox1
    AddItem "cat", Me.ComboBox1
End Sub

Sub AddItem(sItem As String, cmbBox As ComboBox)
    ' adds item retaining alphabetic order
    Dim l As Long
    For l = 0 To cmbBox.ListCount - 1
        Select Case StrComp(cmbBox.List(l), sItem, vbTextCompare)
        Case 0: Exit Sub ' already in the combobox
        Case 1
            cmbBox.AddItem sItem, l
            Exit Sub
        End Select
    Next l
    cmbBox.AddItem sItem
End Sub
 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: sorting items in a ComboBox 
Author Loring Tupper 
Date Mar 21, 2003 
Message Thanks again Kirk,
I tried something similar to what you are suggesting but without the "Me." in front of the ComboBox1 and it didn't work but perhps this minor adjustment will do the trick. Unfortunately or fortunately, depending on how you look at it, I'm off to Cuba for a brief vacation starting tomorrow so I won't get to try it out right away. I will try it a soon as I return and let you know how it goes.

Thanks again for all your kind help.