05-11-2025 09:43 AM
The alternative that I (and many other LabVIEW developers) use is to make use of the Error Line to link functions and sub-VIs that operate sequentially by passing the Error Line from Error Out of one function/sub-VI to the Error In of the next function/sub-VI. If you look at the examples that ship with LabVIEW, such as the many DAQmx examples, you will see that "almost everything sits on the Error Line".
I've created a sub-VI "Template" that I always use when programming. Instead of going to the File menu and clicking "New VI", I click the second entry, "New ..." which I use to navigate (the first time I use it on a new PC) to where I've saved my "New VI Template" file, which I originally created by making a new VI using the default 4-2-2-4 connector pane, and putting Error In and Error Out on the Front Panel, wired to the lower left and lower right corners. I also rename them to "Error In" and "Error Out", which reminds me they are "my" sub-VIs. I then save this "template" VI somewhere I can conveniently find it and save it as a .vit (VI Template) file, naming it something "memorable" such as "TEMPLATE Basic VI.vit".
Now, when I want to create a new VI, I click "New ...", and once I've "found" where I stored TEMPLATE Basic VI.vit, it will appear as the "last used" entry and when I select it, I'll have a new VI with Error In and Error Out on the Front Panel and Block Diagram, ready to be wired and used.
But what (you might ask) if I only need 1 input, and 2 outputs? Can't I use another pattern? Sure, but consistency means the inputs and outputs stay aligned, and your wires "automatically" run straighter. "But what if I need 6 inputs?" Do you really need 6 "unrelated" inputs? Can you bundle them into one "main" input a 5 "parameters" that can be bundled into a Cluster and appear as a single "Cluster" input (or output)?
This will definitely "debulk" your block diagram, making all (or "most") of the items 32x32 pixel squares of functions and sub-VI, with the occasional While, For, and Case structures surrounding them.
Another decluttering method is to group code that does (more-or-less) a single function into its own sub-VI, particularly if "What" it does is much more important than "How" it does it. Hide the messy details inside a 32x32 pixel sub-VI. However, if you do use this "trick" (which basically all advanced LabVIEW developers use), you'll need to find a way to label your sub-VIs. The best developers have mastered the art of creating sub-VI Icons that identify what is contained in that Icon. Those of us (like myself) who haven't quite mastered VI Iconography use the Icon Editor (right-click the Icon in the upper-right corner of the Front Panel or Block Diagram) and chose "Edit Icon" to replace the default Icon that LabVIEW creates.
Once you are there, you need to turn on seeing the "Layers" Tab, which you do by clicking "Layers" on the top menu and choosing "Show Layers page". There you can get rid of the default LabVIEW new VI icon and replace it with a Template, such as an empty Black Square (choose the Rectangle Tool that looks like a Black rectangle outline, click in the Drawing Area and drag down and right). Now go to the Icon Text tab, set Small Fonts, Center alignment (my choice), 10 point, Center Text Vertically, and turn off Capitalize. Now you can write up to 4 (short) lines of text to identify this VI when placed on the Block Diagram.
Making your own sub-VIs is the "secret" to taming huge Block Diagrams. My most complex code (with multiple parallel routines, several hundred VIs, bells and whistles all over) fits on a single 15" laptop screen (of course you don't "see everything", but you do see the "Big Picture", and when you want a Detail, you click on the 32x32 Icon labelled "Messy Detail #1" and (as they say,) "Bob's Your Uncle".
As for using Local Variables, the Big Downside is you cannot see the flow of data (remember, "Data flows through wires").
Bob Schor
05-11-2025 10:16 AM
Wow. I've just downloaded and taken a look at your VI. Observations and suggestions abound.
Like (almost all) LabVIEW Functions, this has Error In and Error Out terminals, so if your code uses the Error Line properly you can place this at the beginning of the Error Line (which should be before your code starts to run) and it will reset all your Controls to their (saved) Default Values (which is why you saved them, above).
Bob Schor
05-11-2025 10:42 AM
@Bob_Schor wrote:
- The "left" edge seems to be initializing Controls (often using Local Variables, a "bad" practice. There's a better way to do this:
- Set all the Controls to the value you want them to have initially. Note that if they are sent to the "normal default" (0 for numerics, F for Booleans, blank for strings), you should leave them "as is" -- many of your Controls fall into this category, but some ("Tab Weight Threshold") have non-zero values.
- Click "Edit" on the Menu bar, and choose "Make Current Values default".
This is useful during development where controls can be changed in edit mode to unusual values before the next run, but once this is a built application (in the end, it always is!), it is no longer needed unless we implement a "reset" state while keeping the program running.
It is also important to only set default values for controls. Often, indicators such as graphs contain massive amounts of data that would only bloat the VI on disk if made the default. (For some background, read this idea). For good measure, I also always set the execution option to "clear indicators when called".
Of course with an overabundance of local variables, the distinction between control and indicator gets blurry, so things get more complicated. But that can of worms has already been opened here... 😄
05-11-2025 11:45 AM
@Faisal786 wrote:
Its very easy to suggest someone to throw their 3 years of work and abusing their way of work but it is not welcome at all.
1) i have not left these blank spaces on purpose, i am also pissed of why they are their as clean up tool is not helping.
2) i have plenty of local variables because i read somewhere on forum that creating local variable is better than entering or leaving millions of wires from structures.
Open to have any constructive feedback and suggestion.
My advice is sincere. You may not want to hear it, but I believe that those three steps I mentioned really are the best course of action.
05-11-2025 11:52 AM
@Bob_Schor wrote:
...
The best developers have mastered the art of creating sub-VI Icons that identify what is contained in that Icon.
...
Bob Schor
Gee, that's disappointing to hear. It should be 'most developers', not "The best developers".
05-11-2025 04:48 PM
@altenbach wrote:
@Faisal786 wrote:
i have plenty of local variables because i read somewhere on forum that creating local variable is better than entering or leaving millions of wires from structures..
A bold and completely false statement require a link. Can you tell us where you read that? All I can think of is that this was a newbie statement that quickly got challenged by more experienced users.
One of my former cow-orkers would use "Value" property nodes all over because he heard that local variables "cause race conditions".
05-12-2025 12:45 AM
@paul_a_cardinale wrote:
@Faisal786 wrote:
Its very easy to suggest someone to throw their 3 years of work and abusing their way of work but it is not welcome at all.
1) i have not left these blank spaces on purpose, i am also pissed of why they are their as clean up tool is not helping.
2) i have plenty of local variables because i read somewhere on forum that creating local variable is better than entering or leaving millions of wires from structures.
Open to have any constructive feedback and suggestion.
My advice is sincere. You may not want to hear it, but I believe that those three steps I mentioned really are the best course of action.
Paul is right. Instead of spending three years of creating this, you could have learned to program and made it in much less time and have fewer issues in the future. But, as they say, the best time to plant a tree is 3 years ago, but the second best is now. Continuing to program like this will only get you into more trouble and headache, but now you have the opportunity to learn and improve.
05-12-2025 05:36 AM
Hi Bob,
Thanks a million for spending time on my case and giving me a very detailed feedback. I am already working on your and other member's feedback.
05-12-2025 07:12 AM
The Automatic clean up is unfortunately not very good. It works ok on small sub-vi's. In this case you'll have to fix it yourself.
Most things are mentioned, but i'd like to add a State Machine-architecture. Check out Help -> Find example -> State machine fundamentals, it'd help you structure and organize your code.
You can do a lot of cleanup by similar things like this and it'll save you space. (ctrl+alt+l mouse to contract diagram)
05-12-2025 07:31 AM - edited 05-12-2025 07:42 AM
Hi,
The whole sum+comparison only makes sense for integer values of those "powder concentrations" (rule: "never compare floats for equality", almost).
So the array should be blue and there should be only one comparison "<2" (or ">=2")…