LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I create "variable array"?

Is it possible to create an array of variables? Eg. if I have to 10 boolean control, called Switch1, Switch2... Switch10, and I need to switch one of them to ON, but which one to switch on depends on different situation. Say, at situation A, I need to switch on Switch3, then at situation B, I need to switch on Switch5, etc. Can I write just one command, with the switch number as the input, so that it can switch on different boolean control (Switch#) at different time? (i.e. treating the variables Switch1 to Switch10 as an array of variables called Switch#).
BTW, this question was asked by another LabView user in 2000, but there hasn't been a satisfactory anwer.
0 Kudos
Message 1 of 18
(4,083 Views)
As you've written it, there are probably a dozen ways to solve the problem. One attempt is attached, written in LV6.0.2.

If you can't use an indicator to write to, remember that controls can be written to using locals.

Good luck.
0 Kudos
Message 2 of 18
(4,083 Views)
Thanks for your answer. Often the variables are not together, ie. they are not in a row or column, but instead are scattered in the panel, so the simple array function won't work. Attached VI shows the way that I've been doing it. But it still requires me to control each switch individually and use large amount of functions such as "array subset", "replace array subset" (one for each variable).
Is there a way to have the variables at different position on the panel, yet use one command to control all of them?
0 Kudos
Message 3 of 18
(4,083 Views)
Array of different elements is a cluster!!!!!


"pji" schreef in bericht
news:506500000008000000F05F0000-1031838699000@exchange.ni.com...
> Is it possible to create an array of variables? Eg. if I have to 10
> boolean control, called Switch1, Switch2... Switch10, and I need to
> switch one of them to ON, but which one to switch on depends on
> different situation. Say, at situation A, I need to switch on Switch3,
> then at situation B, I need to switch on Switch5, etc. Can I write
> just one command, with the switch number as the input, so that it can
> switch on different boolean control (Switch#) at different time? (i.e.
> treating the variables Switch1 to Switch10 as an array of variables
> called Switch#).
> BTW, this question was asked
by another LabView user in 2000, but
> there hasn't been a satisfactory anwer.
0 Kudos
Message 4 of 18
(3,972 Views)
I can think of one way off the top of my head, but it suffers from some fundamental flaws, and I'm not entirely familiar with the functions involved, so it may not work!

The solution:
It is possible to open a reference (using the Open VI Reference) to the VI being run. From there, it is possible to obtain a reference to all of the controls on the front panel using property nodes. Using these references, it should be possible to set the properties of the controls.

The flaws: It's complex, it's large overhead, and it's virtually impossible to maintain.

I've run into the same problem before with controls embedded in tab controls, since buttons on two different tabs cannot belong to the same cluster or array. I have yet to see a solutio
n that I like.

Perhaps someone else out there has seen a good solution for this one? Or maybe NI will bite the bullet and implement heterogeneous arrays and "virtual" clusters (clusters who's front panel objects are not spatially associated 🙂

Sorry I can't help more.
0 Kudos
Message 5 of 18
(4,083 Views)
Here is example of what I sometimes do when a bunch of different controls need pretty much the same code applied to them.
Message 6 of 18
(3,972 Views)
If it is what you need, store internally the values in an array in the shift register but display them in a cluster. Use Array to Cluster function to convert the array.


LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 18
(4,083 Views)
Thanks. It's helpful. This is the best solution I've got so far.
0 Kudos
Message 8 of 18
(3,972 Views)
The example by "VI guy" below is basically similar to what you suggest. Thanks for your help.
0 Kudos
Message 9 of 18
(4,083 Views)
Thanks for your comment. Sorry I can't open your file, an error was shown, don't know why. My LabView version is 6i.
0 Kudos
Message 10 of 18
(4,083 Views)