INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to get the level of a menubar item

How to get the level of a menubar item

(OP)
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

RE: How to get the level of a menubar item

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

Level1
Level2
[indent]
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

RE: How to get the level of a menubar item

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)

RE: How to get the level of a menubar item

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.

RE: How to get the level of a menubar item

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?

RE: How to get the level of a menubar item

>I don't understand that

What if you have more than one item at each level?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close