04-13-2011 07:45 AM - edited 04-13-2011 07:47 AM
Example of both Local and Global variable abuse:
http://forums.ni.com/t5/LabVIEW/Downconvert-VI-Requests/m-p/1522520#M567682
small snapshot:
Since this is inside a While Loop, using wires and shift registers is the way to go.
Obviously misunderstanding text-based Global variable declaration with LabVIEW's Global..
04-13-2011 02:24 PM
I hope this hasn't been posted before.
Someone actually put this up on their commercial site.
04-23-2011 11:39 AM
Using Locals where a wire you do the trick, and shift registers would provide dataflow (hint: it's inside a loop).
04-23-2011 12:06 PM
Ray, do you have a link where you saw that?
There are other glaring mistakes, for example a loop containing an event structure inside a sequence frame. This could be disastrous unless the code is very carefully constructed. There is also no error handling where it is most important: at the port configuration.
04-25-2011 08:59 AM
Oops sorry.
It was found here:
http://forums.ni.com/t5/LabVIEW/Reading-time-interval-of-serial-port/m-p/1534282#M569644
04-27-2011 09:27 AM
I do not know if I'm allowed to post this, because it is from the LabVIEW Design Guidelines from National Instruments. I think those guidelines are available on this website, so I will post it anyway..
This is why I created this thread... Unfortunately, it seems that most people do not follow the recommendation to avoid abuse of Local Variables. They are not inherintely bad if/when used correctly, but as you can see through all the posted examples, people do abuse them too often..
From NI Guidelines:
"Avoid using local variables when you can use a wire to transfer data. Every local variable that reads the data makes a copy of the data. Use global and local variables as sparingly as possible.
05-11-2011 10:05 AM
That's a short and good description Ray/NI as to how to use Locals. The 3rd point isn't completely true though, but if create a AE/FGV with error wires (and use them) you can make it race secure ... assuming you dont use it in several threads/loops in which case it might still be an issue.
/Y
05-12-2011 07:14 AM
@Yamaeda wrote:
assuming you dont use it in several threads/loops in which case it might still be an issue.
That's why it's in there... 😉
I am looking at code which has 3 loops running in parallel, but they each have a flat sequence structure around them and shared variables with the error cluster wired through. But they read & write in parallel!!!!!
05-12-2011 02:06 PM - edited 05-12-2011 02:08 PM
05-23-2011 08:48 AM
I wish I could post an image, but if I did you'd need a telescope to look at it since the designer apparently had the same size monitor used to track the shuttle's orbit over the earth. The code seems to have more local variables than actual code. You can see the glory here: http://forums.ni.com/t5/LabVIEW/Downconvert-VI-Requests/m-p/1569398#M576151