10-23-2014 01:58 PM
Hello,
I'm trying to find an efficient and clean way to do an action tha can be triggered by different things without having to repeat the piece of code itself at various places in my VI (after the said trigger things).
An example (because my explanation is pretty clumsy):
- The "action" (piece of code) is reading a file displaying the results (tiny more complicated than that but that shows the idea)
- I want that action to happen when for example I save data in the file, open an existing file or press a button
- Right now Im using the same piece of code at each places (when I write in the file, open existing file and press the button) using local variables
I'm trying to find a more efficient way to do that, so I can write the code only once.
FYI the whole thing is in a big while loop. The VI Im working on is pretty huge and complex so It doesnt really make sense to share it.
Hope my question is clear. Thanks !
10-23-2014 02:26 PM
Hey, it's always best to simply create a subvi when you use the same code multiple places in your program. You can actually just highlight the piece of code and click edit-create subvi. This is the best way to go. Here is a link that shows screenshots.
http://www.ni.com/white-paper/7593/en/
Good Luck.
10-23-2014 02:32 PM - edited 10-23-2014 02:40 PM
I was actually thinking about subVI but was wondering if it was the best way. One little problem is that I have multiple indicators I need to update so I still have to connect the subvi to local variable of the said indicators.
10-23-2014 02:52 PM
Currently this is the temporary way I found to do what I want
Now that I see it I could just put the "refresh" button as a non-latch /non-release and change it to true when needed in my code.
10-23-2014 03:09 PM
A good state machine could handle this easily. And it might even get you to not use local variables.
10-24-2014 07:36 AM
Definitely without a doubt use a state machine. You most-likely won't have to use local variables. Labview has good templates and examples of the state machine architecture.
10-24-2014 02:08 PM
Ok thanks. I know nothing about state machine, I'll do some googling.
10-24-2014 02:15 PM
Application Design Patterns: State Machines
10-24-2014 02:19 PM
Good Luck