Adding menu items at run-time

I want a SIMPLE, EASY, and CLEAN way to add menu items at run-time.
I have the menu "Languages" that will contains a variable number of items, depending on the number of languages set by the program.
So, let say this number is set to 3 (English, French and Spanish), I want the program to add these 3 languages as menu-items at run time.

thanks!
SylvaniaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You could use the Load method.  With one menu sub-item in Languages mnuLanguage(0).  Set caption to "English".  Load new menu items:

Load mnuLanguage(1)
mnuLanguage(1).Caption = "French"
mnuLanguage(1).Visible = True

Load mnuLanguage(2)
mnuLanguage(2).Caption = "Spanish"
mnuLanguage(2).Visible = True

This could become a more complicated routine, but is this what you want?
0
SylvaniaAuthor Commented:
Yes, I had that in tought, but I want to handle an infinite languages possibility... altough I know there is not such a number of 'em down there! lol
Let say I just want to know the clean way to do the job, without hidding anything; just ADDING menu-items at run-time.

thanks!
0
Erick37Commented:
This will create new sub-menu items provided you already have one sub-menu (named mnuLangs) with an index of 0.
mnuLangs is the sub-menu of the top level Languages item.

Private Sub Form_Load()
    'Create new sub-menu entries
    'mnuLangs(0) already exists as "English"
    Load mnuLangs(1)
    mnuLangs(1).Caption = "French"
    Load mnuLangs(2)
    mnuLangs(2).Caption = "Spanish"
End Sub

Private Sub mnuLangs_Click(Index As Integer)
    Select Case Index
    Case 0
        Debug.Print "English"
    Case 1
        Debug.Print "French"
    Case 2
        Debug.Print "Spanish"
    End Select
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
The possibilities for doing are almost infinite.

Something simple, like:

Private Sub LoadLanguages()

Dim vLanguages As Variant
Dim iMenu As Integer

   vLanguages = Array("English", "French", "Spanish", "German", "Italian")

   For iMenu = LBound(vLanguages) To UBound(vLanguages)

      If iMenu > LBound(vLanguages) Then
         Load mnuLanguages(iMenu)
      End If
     
      mnuLanguages(iMenu).Caption = vLanguages(iMenu)
      mnuLanguages(iMenu).Visible = True
   
   Next iMenu
   
End Sub

You could add each language to the array as needed.

You could also use databases and tables.

When using the Load statement, the new menu items will not be visible, so you need .Visible = True
0
SylvaniaAuthor Commented:
Thanks to you too, The learned one!
I just can't believe it was this simple!
With all the people saying to use api, and other stuff... the old LOAD was the key! lol

thanks pals!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.