Link to home
Start Free TrialLog in
Avatar of Sylvania
SylvaniaFlag for Canada

asked on

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!
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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?
Avatar of Sylvania

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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!