LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Micro-Nuggets !!! ~~~~ Post 'em if you got 'em

Some people might find this useful, basically its a way of being able to manage lots of constants without having heaps of vis or risking using global variables.

The idea is to use different enum type defs for each data type and then use a polymorphic vi to select the constant and return it.

What you end up with is this

const.PNG

I should add that this is a bit more complicated in terms of setup so only really useful if you have more than 3 or 4 constants of a type. But once it's set up you can copy the vi's and type defs between projects, easily add remove or modify constants and the block diagram representation is very neat and says exactly what it is. I've attached a zip showing the implementation for 2 different types but it can be extended to as many types as you like.

0 Kudos
Message 261 of 368
(1,553 Views)

@tobyscott wrote:

Some people might find this useful, basically its a way of being able to manage lots of constants without having heaps of vis or risking using global variables.


What's wrong with using a global variable VI for holding constants?  They are very efficient and you can store them all in 1 file.  And you don't have the complexity of having an enum and VI for each data type.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 262 of 368
(1,524 Views)

Basically because there is a risk that you (or more likely someone else using your code) write to them and it screws your code up somewhere else. Basically an extra layer of protection. There is some good talk about it here if you haven't seen http://forums.ni.com/t5/LabVIEW/Community-Nugget-04-23-2007/m-p/510961

0 Kudos
Message 263 of 368
(1,517 Views)

Use an Action Engine without a write method.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 264 of 368
(1,505 Views)

Action Engines are fine until you need lots of them, then your project is also littered with vi's, one for each constant. This reduces that number to two for each type, which can quite often be less. Also the code can be modified to implement more actions if necessary (although that kind of defeats the purpose of a constant).

I'm not saying this is the best method, just a viable method maybe some haven't considered

0 Kudos
Message 265 of 368
(1,497 Views)

Use Worm.  One functional global, all variables.  I've tried to expand on worm and make a Variant Repository which supports Write Once, reading and writing to disk, type adaption, and it has an example showing how it can be used with a functional global or action engine.

0 Kudos
Message 266 of 368
(1,490 Views)

@crossrulz wrote:

@tobyscott wrote:

Some people might find this useful, basically its a way of being able to manage lots of constants without having heaps of vis or risking using global variables.


What's wrong with using a global variable VI for holding constants?  They are very efficient and you can store them all in 1 file.  And you don't have the complexity of having an enum and VI for each data type.


Agreed. Refreshing to see some of the "Globals are evil" nonsense go by the wayside, occasionally. Seen my share of action engines and god clusters lately.

Richard






Message 267 of 368
(1,419 Views)

@Broken_Arrow wrote:

Agreed. Refreshing to see some of the "Globals are evil" nonsense go by the wayside, occasionally. Seen my share of action engines and god clusters lately.


I can't seem to find it at the moment but there was an interesting comic that showed begginner using a Global, intermediate using a shift register, advanced using a VIG, and guru using a global again.

 

You won't find a global (native global) in any of my applications, but you also won't here me saying they should be banned.

Message 268 of 368
(1,416 Views)

Hooovahh wrote: I can't seem to find it at the moment but there was an interesting comic that showed begginner using a Global, intermediate using a shift register, advanced using a VIG, and guru using a global again.

I don't remember where it is hiding either.  Luckily, I made a copy of it...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 269 of 368
(1,396 Views)

Oh, the Irony, that's one of mine! Smiley Very Happy

Richard






0 Kudos
Message 270 of 368
(1,388 Views)