LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Menu help, and How to dynamically change case statement?

Hi everyone,
 
I have written lv7.1 code which relies heavily on the user run-time menus.  There are several menus which are present at the start of the code, and then several that I generate based on files that are on the system.  I want to link the generated menus, which are no more than filenames under a predetermined menu heading, to a case statement such that when the "Menu Selection (user)" event fires I can have a case statement for each one of these generated menus.
 
More clearly (maybe):
At start, menus {A, B, C, D, E, F} exist.
Right after start menus are generated such that the menus are now {A, B, C, D, E [1,2,3,4,5...], F[1,2,3...]}.
 
How do I act upon the user selecting any of the submenus to E & F which were generated dynamically?  I do not know how many menus there will be each time, nor what their titles will be.
 
Is there a way to dynamically create case statements within an already existing case structure?
 
Thanks,
 
Jonathan
0 Kudos
Message 1 of 7
(3,375 Views)
I do not believe that there is a way to dynamically create a case in a case structure, but you can create and register dynamic events.

Look in the example finder for "Dynamically Register For Events.vi".

Hopefully you're able to use events instead of a case structure.
Message 2 of 7
(3,368 Views)
If you were to generate dynamic cases for the new menu items, what you put in the new case to handle the code?

Would each of the new cases have to have specific code or would it be generic code that can handle whatever is selected.

If you want to delv into the world of LabVIEW Scripting, you should be able to dynamically create new cases and put whatever code you need in each new case. Not a trival effort, but it can be done. Check out the :LAVA Scripting baords.

Otherwise, you might want to look into using dynamic events. There's a pretty good example of how to register dynamic events that ships with LabVIEW. Open the Example finder and search for "register event". That should get you to it. This would let you create several generic events that you could register to the new menu items as they are needed.

Does that help any?

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 3 of 7
(3,365 Views)
As stated in the previous posts, it's going to be difficult to have case statements for each dynamically created item. My suggestion: If you create the menus during runtime, use "good" menu tags and parse them in the default case.
Example: For the E-subitems use menu tags like "E-name1", "E-name2", and so on. For the F-subitems "F-name1", ... Then parse the menu tag in the default case, i.e. split the tag to "E" and name1. At this point you can use a case structure with cases "E", "F", ... and handle the menu event according to name1.
I hope this description isn't too complicated, unfortunately I don't have LabVIEW here to give you an example.

Hope this helps,
Daniel

Message 4 of 7
(3,353 Views)

Thanks for all the help,

Though this is part of the problem, maybe there's another way around it that I'm not familiar with (I'm not familiar with a lot of labview things 🙂 )

I use the event structure to fire event "Menu Selection (user)", then inside that event I use the tag name and path data provided along with case statements to select what to do when a specific menu has been chosen.  How else could I use events to choose what menu has been chosen?  Can I register each menu as its own event somehow?

 

thanks,

jonathan

0 Kudos
Message 5 of 7
(3,328 Views)

Nevermind, thanks for the help all... I found a solution.

 

In the 'Menu Selection (user)' event structure, there is a case statement to decide which static menu item was chosen from the name and tag path... I setup the default case for that case statement (which ends up being any menu that was created dynamically, if you create cases for all static run time menu items) such that once it is inside the default case it can then refer to the data from which the dynamic menus were created and the menu path to figure out which one was chosen.

 

Maybe not the best method, i dislike having too many case statements, but it works! 😉

0 Kudos
Message 6 of 7
(3,320 Views)
Glad you found a solution. It's basically what I tried to say in my previous post Smiley Wink
I'll try to attach a code snippet next time.

0 Kudos
Message 7 of 7
(3,314 Views)