From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

menu path

Solved!
Go to solution

I have an application which builds menus dynamically by using the Insert Menu Items vi.

 

Sometimes I have two drop down menus and I want to put an item in both of them with the same text.  In both menus I do an insert menu with the same text for both the item name and the item tag. 

 

Labview (understandably) wants item tags to be unique so the tag for the item in menu 1 is abc and the tag for the item in menu 2 is changed to abc_1.  Both menu 1 and menu 2 show abc in the drop down list.  I'm OK with that.

 

Then the user chooses abc from menu 2 and labview returns the tag abc_1.  But it also returns the path as menu 2:abc_1 which to me makes no sense at all.  Why doesn't it return <menu name>:<item name> since this is unique and is much easier to deal with?

 

David

 

0 Kudos
Message 1 of 9
(2,995 Views)

Can you post your code? I can't say I have ever seen this behavior as I always explicitly specify the tags for the menuitems I create.

 

Mike...

 

 


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 9
(2,985 Views)

Here is a small program which demonstrates the behaviour. 

 

First create three menu items by entering a few letters in the three controls.  Note that both menu 1 and menu 2 are identical.  Then go to the second tab and select menu items.

0 Kudos
Message 3 of 9
(2,970 Views)

Hi David,

 

even when you call them menu1 and menu2 and even when you think of them as two independent menus: they are still belonging to the very same menu!

 

You should easily notice that from the fact that you're using the "current VIs menu" call. You are adding items to the VIs menu. All the items have to have unique tags. As you don't provide them LabVIEW has to add those "_1" to the tag to enable you to differ between them. After all: it's just one menu! Usually you only work later on by parsing the tag. The path is irrelevant (most times) as you only work with the tag...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(2,959 Views)

If you don't like the tags that LV auto generates you should supply your own. Then you can have items with the same name on two different menus.

 

(BTW: a little clarification in terminology, there are two menus being created but they reside on the same menubar. A window can only have one menubar, but that menubar can house multiple menus.)

 

I'm also not clear why you go to the trouble to have a button read what the last menu selection was. Why not simply define a menu activation event to return the path and tag each time a selection is made without additional buttons.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 9
(2,947 Views)

Thank you, Mike and Gerd for your replies.  I really appreciate it.

 

I have a few comments:

 

1.  I think you are saying "It works that way because that's the way it works."  Fine.  I have to accept that but I don't have to like it.  Obviously somebody made a decision a long time ago and it can't be changed because thousands of programs would break.  But the decision could have been made the other way;  that each menu on the menu bar is an independent menu which can have items with the same tag.

 

2.  The return of the path with the tag at the end instead of the name at the end seems to me to be flat out wrong. I think it would be easy for NI to implement a new vi "get menu true path" which would return the complete path with the name at the end.  I think it would make life easier for anybody building dynamic menus.

 

3.  Mike asked why I implemented a button to show the path and tag rather than simply creating a Menu Application event handler.  First of all, what I sent you was simply a vi created to demonstrate the issue I raised, not a real program and I wanted to get it working as quickly as possible.  But I tried what you suggested.  I created a Menu Application event handler and then I put the get menu selection vi inside of it.  I invite you to try it.  I think you will be surprised by the result.  The tag and path displayed is always one behind the last item chosen from the menu.  Don't ask me why.

 

Regards and thanks, again,

 

David

 

0 Kudos
Message 6 of 9
(2,933 Views)


3.  Mike asked why I implemented a button to show the path and tag rather than simply creating a Menu Application event handler.  First of all, what I sent you was simply a vi created to demonstrate the issue I raised, not a real program and I wanted to get it working as quickly as possible.  But I tried what you suggested.  I created a Menu Application event handler and then I put the get menu selection vi inside of it.  I invite you to try it.  I think you will be surprised by the result.  The tag and path displayed is always one behind the last item chosen from the menu.  Don't ask me why.

 

 

David

 


That's because you are not supposed to use a "Get Menu Selection" VI within an event structure. Simply use the "Menu item" or "Menu Path" terminal/thingy to the left of your event case (sorry I don't have LV in front of me to name things as they should, but I hope you get the meaning). That will give you exactly the last activated menu item.

0 Kudos
Message 7 of 9
(2,925 Views)
Solution
Accepted by topic author David_Lieberman

Hi David,

 


1.  I think you are saying "It works that way because that's the way it works."  Fine.  I have to accept that but I don't have to like it.  Obviously somebody made a decision a long time ago and it can't be changed because thousands of programs would break.  But the decision could have been made the other way;  that each menu on the menu bar is an independent menu which can have items with the same tag.


 - Well, the menu/menubar works like a tree structure of tags. Each tag has to be unique. That's it. Even when you would like to prefer independent menus in the menubar (just because you have duplicate tags, but that is your fault) - most of us (I presume) still like/prefer/depend on the complete tree of unique tags of a single instance of a menubar...

- You can circumvent your problems by making the tags unique, I would suggest something like MenuName_TagName. You still can handle different (but unique) tags with the same case of a case structure. Remember: the tag is all you need to handle a menu selection and you get it from the event structure presented as a string...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 9
(2,914 Views)

-------------------------------------------------------------------------

That's because you are not supposed to use a "Get Menu Selection" VI within an event structure. Simply use the "Menu item" or "Menu Path" terminal/thingy to the left of your event case (sorry I don't have LV in front of me to name things as they should, but I hope you get the meaning). That will give you exactly the last activated menu item.

 -------------------------------------------------------------------------
I did what you suggested (wired item tag and item path from the "left side thingy") and it works.  
There is nothing I could find in the labview documentation which says you should not use a Get Menu Selection in an event structure and no error is indicated at runtime.  All you get is an unexpected result.  Sometimes I feel like a rat in a maze when developing in Labview; "well, the cheese isn't here.  I guess I'll have to try something else."
Thanks for your help.
0 Kudos
Message 9 of 9
(2,895 Views)