04-23-2007 09:24 AM
If your code needs to be secure, then this would be a security hole and not usable at all.
04-23-2007 09:42 AM
04-23-2007 09:51 AM
04-23-2007 09:55 AM
04-23-2007 10:08 AM
For constants I use the same approach as toni. A single subvi that returns a constant. This provides a level of protection against writing to the global anywhere in the code. Here you go into the subvi and change the constant that the output is wired to. You have a single instance to change to fix the entire codes constants. Another adcvantage I have found with using a subvi as a constant is to allow for an informative icon (such as pi) to indicate the constants use. I have another type of constant vi I use for allowing "pre-binding" the constant value. Here the vi will look in the default ini file for a key in the section constants->constant name and initialize a shift register with the new constant value in a file. If the file or value doesn't exist, a default value is used. A good case for this is a constant called simulate in a daq system. The constant is by default false, but when I debug the system I just add the flag simulate = 'true' and my "constant" will change on the next execution. I still avoide globals but admire there ease of use. This has always been a hotly contested topic.
Paul
04-23-2007 10:17 AM
04-23-2007 10:20 AM
Tomi, the main issue with a VI is that you have to create a file and icon for each VI. If you have one or two, that's easy, but if you have a lot, it would be hard.
As you mentioned, a big advantage of using VIs as constants is that they can have code in them, so your constant can have complex conditions (and it would be much harder for a user to misuse them).
Greg, if you can gurantee that the read happens before anything else happen (and if you can handle corner cases like if the file is not found) and your global is only written to in one place, you should be fine. Since you say you save the global, I assume that means the value is written to from more than one place and you might have race conditions. In any case, the case you mention is different from I refered to, since constants are defined in the code, not in configuration files.
04-23-2007 10:31 AM
04-23-2007 10:44 AM
04-23-2007 10:45 AM
Good Nugget Topic tst!
I'm still in the sub-VI camp on this topic because they have a diagram which gives more more flexibility. They also can tolerate type definitions changing without loosing the desired values.
Ben