About   -   Contact   -   Purchase   -   Search   -   What's New

VB Menu Options
The menu editor in VB is great for creating simple menu structures, but menus displaying options employing checked entries require some additional coding behind the menu objects. If you're familiar with the menu editor, then creating menus such as the File menu with Open, Save, Print and Exit entries etc. is straight forward. The event handling behind these menus is also simple, as follows:

Private Sub mnuOpen_Click()

   'code to open and retrieve appropriate files...

End Sub

Similarly the menus for Save and Exit are handled separately with the mnuSave and mnuExit click events.

However, option menus such as the one below require some additional coding to reflect the option status as follows:

Private Sub mnuShowOK_Click()

   If mnuShowOK.Checked then    'don't show OK bttn
	mnuShow.Checked = False
	cmdOK.Visible = False
	mnuShow.Checked = True 'show OK bttn
	cmdOK.Visible = True
   End If

End Sub

Menu options containing multiple entries (as shown below), that are mutually exclusive are handled with menu control arrays as follows:

Private Sub mnuDragDrop_Click(Index As Integer)

   'Index 0 - Enable Drag and Drop
   'Index 1 - Disable Drag and Drop

   If mnuDragDrop(0).Checked and Index = 1 then
	mnuDragDrop(1).Checked = True
	'code disabling functionality
   ElseIf mnuDragDrop(1).Checked and Index = 0 then
	mnuDragDrop(0).Checked = True
	'code enabling functionality
   End If

End Sub
The If...ElseIf statement may look a little confusing, but basically,
   If mnuDragDrop(0).Checked and Index = 1 then
determines if  'Enable Drag and Drop' is checked and also if  'Disable Drag and Drop' is selected and if both these conditions are met then 'Disable Drag and Drop' is checked instead. Obviously, the opposite is applicable for the ElseIf statement. No other conditions are required such as,
   If mnuDragDrop(0).Checked and Index = 0 then
this would be pointless, because if  'Enable Drag and Drop' is checked and 'Enable Drag and Drop' is selected then nothing needs to happen as 'Enable Drag and Drop' is already the chosen option. Options groups with more than two choices can be handled this way, but if more than one option group exists under the same menu heading then separator bars should be used for clarity as follows:


Top of Page

Legal Notice

Ken Howe 2011