Link to home
Start Free TrialLog in
Avatar of hpet
hpet

asked on

Menu at run-time

Hi,

I use VB6.
How can i add new topics to menu at runtime?
How free am i modifing menu at runtime?

-Peter
ASKER CERTIFIED SOLUTION
Avatar of jjbyers
jjbyers

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
Avatar of mawe
mawe

Create a control array e.g. mnuFileItem(0), mnuFileItem(1) and so on at design time. Then set the visible property to False for the blank menu controls, and set the visible property to True once you've added text in a control.

Here is an example of some menu items being added at run time.  This is based off of a table with some names that are inserted into the menu.  Hope this helps.

rstNames is the recordset that contains the names.
mnuFileOpenName(Name_Idx) is the menu item array.  During design time, set the index property to zero.

Do Until rstNames.EOF

      If Name_Idx > 0 Then
          Load Me.mnuFileOpenName(Name_Idx)
'Here we are loading the next instance of the menu item, we only load if it is greater than zero because the menu item with index zero was created at design time.
      End If

        Me.mnuFileOpenName(Name_Idx).Caption = rstNames!Name 'set the caption for the new menu item
      Me.mnuFileOpenName(Name_Idx).visible = true 'showing the new menu item
        Name_Idx = Name_Idx + 1 'increment the load index
        rstNames.MoveNext 'move to the next record

    Loop
Avatar of hpet

ASKER

Sorry for delay...