LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to add items to a case statement from front panel

Hello all,
 
I have an application that I have written which runs one of two sequences based on a manufacturer part number.  I currently have it set up so that the user can select a part number from a drop down box on the front panel, and based on the selected number a local variable is set that chooses which sequence to run.  So its basically a drop downmenu attached to a case sequence which sets a variable.
 
What I would like to do is be able to have a pop up window or .vi that allows the end user to add part numbers to the application, and choose which sequence to associate with that part number.  Let me give this example.
 
Part 123456 uses serial communication and needs sequence 1
Part 123457 uses CAN communication and needs sequence 2
 
User would be given a textbox where they would enter the new part number, and a drop down box that gives them the option of CAN/Serial.  They would then hit a "save" button and the serial number and corresponding communication option would be saved as a new case. 
 
Is this possible??  I am fairly proficient, so a basic example should help me a lot.
 
Thanks in advance.
 
Speedbump
 
 
0 Kudos
Message 1 of 9
(3,851 Views)
I would use a cluster array.  The cluster would contain the part number and the sequence number.  You can write a vi that would allow the user to type in the cluster information.  Then in your main vi, you could display the part numbers in a list.  When the user selects a part number, find that part number in the cluster array, and then get the sequence number from that cluster.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(3,835 Views)
You can't create new cases dynamically. Instead of wiring the part number to a case statement, you can do a lookup in an ini file and determine the the sequence name and communication mode. For example, if you have part number 123456, in the ini file might be keys called 123456_com and 123456_seq with values of 'serial' and 'sequence 1'. These values would be wired to case statements. When it's time for the operator to add a new part number, two more entries in the ini file would be made. This way, you never have to create any more cases than you already have.
Message 3 of 9
(3,834 Views)

Thanks.  I'll research the .ini option and see if I can get it to work. 

 

Any other ideas are appreciated as well;)

 

 

0 Kudos
Message 4 of 9
(3,809 Views)
Ahhhhh...gone are the good ol' days of writing self-modifying code.....
0 Kudos
Message 5 of 9
(3,771 Views)
Bill wrote "Ahhhhh...gone are the good ol' days of writing self-modifying code....."
 
Please see the code CC posted in reply # 29 of this thread
 
 
I'd say the "good ol' days" are happening now!
 
Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 9
(3,752 Views)
This particular application could be efficiently written as a queue-driven state machine.  The sequence the user selects is then an array of commands placed on the queue.  This allows you to reuse tasks in both sequences.  It also allows you to efficiently branch or halt on errors.  You can convert your current sequence code pretty easily.  Replace the sequence with a case statement and select with the output of a queue.  The queue element can be a strict typedef enum (my normal favorite), a string (easy to debug and dynamically change), or a simple integer (fast, but hard to maintain).  Wrap the whole thing in a WHILE loop.  You will need to add an exit case to exit the loop at the end of the sequence.  Any sequence locals can be reimplemented as shift registers (easiest and fastest, use one shift register with a cluster of your variables), LV2 globals, or queue-based globals.

If you are interested and need more info, let me know.  I can post a simple example.
0 Kudos
Message 7 of 9
(3,741 Views)
Actually, I was being facetious...self-modifying code is a terrible idea. Ever try to debug it? All of my old computer science professors would get violently ill at the thought.
0 Kudos
Message 8 of 9
(3,716 Views)
Didn't mean to get this discussion started. By posting it that way, I got alternatives to doing it the wrong way, and it is now working. Thanks for all of your help. Erik
0 Kudos
Message 9 of 9
(3,703 Views)