Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Popup Menu

Status
Not open for further replies.

kunai

Programmer
Jun 4, 2004
52
CA
Hi,

I'm trying to figure out if it's possible to sort a popup menu programatically.

I need to sort my popup menu because i change their captions depending on language.

Using VB6.

Thanks
 
You can create the menu dynamically...

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
Yes but you need to have names as arrays: mnuItem(0), mnuItem(1) ...etc.

Then the next important is (as the sort order changes the location of items) the way that the code for each click is executed. I mean: mnuItem(0) has caption "bla", in other language its caption will be "hello".

So:

Code:
Private Sub mnuPopUp_Click(Index As Integer)
  Select Case mnuPopUp(Index)[b].Caption[/b]
    Case "bla", "hello"
      ' code
    
    Case ...
      ' code
  End Select
End Sub

To sort them:

Code:
Dim i, j As Integer
Dim temp As String

For i = 1 To mnuPopUp.UBound
  For j = mnuPopUp.UBound To i Step -1
    If mnuPopUp(j - 1).Caption > mnuPopUp(j).Caption Then
      temp = mnuPopUp(j - 1).Caption
      mnuPopUp(j - 1).Caption = mnuPopUp(j).Caption
      mnuPopUp(j).Caption = temp
    End If
  Next
Next

The index of the first must be zero.




-bclt
 
I was in the process of coding something like that.
I think that should work great.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top