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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the level of a menubar item

Status
Not open for further replies.

JelladTarek

Programmer
Dec 1, 2017
1
0
0
TN
Hello
i'm using vb6, and i want to get the level of a menubar item, for exemple if we have this menu

File
...New
...Close
...XXX
......yyy

the level of "File" is 1
New, Close, XXX have the same level 2
the level of yyy is 3

thank you
 
In the menu editor you could try assigning indexing. I create a three level menu and assigned indexes:

Level1
Level2
Level3

I assigned indexes

Level1 = 1
Level2 = 2
Level3 = 3

This will show:

1
2
3

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is Menu Then
Debug.Print ctl.Index
End If
Next ctl​
 
VB itself doesn't have any easy way of getting this sort of information. You either have to use a technique such as suggested by SatlyThecfrog above, or resort to using the API (and even there it isn't straightforward)
 
Instead of using Index for this purpose, I would suggest using the Tag property which is more suitable for storing some auxiliary data. The Tag property is not visible in Menu Editor window. You must use the Properties window to initialize Tag property after defining the menu structure.

If you use Index to store the menu depth, you won't be able to access or refer to that menu item unless you know the Index in advance. This will make the code more confusing and you won't be able to query the menu depth unless you know it which makes the whole exercise futile.

For example, if the name of File menu is mnuFile, you won't get its index or menu depth using mnuFile.Index. Instead you would need to get the Index using mnuFile(1).Index which means that you must mention the Index you are trying to retrieve.
 
For example, if the name of File menu is mnuFile, you won't get its index or menu depth using mnuFile.Index. Instead you would need to get the Index using mnuFile(1).Index which means that you must mention the Index you are trying to retrieve.

I don't understand that. The example I posted lists the levels via the index. What I mean is the design was the top was one to the bottom which was three. The assumption was the menu was designed to accommodate the need. What am I missing?
 
>I don't understand that

What if you have more than one item at each level?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top