From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you initialize a large number of variables neatly

Solved!
Go to solution

I have a large number of variables (say 20 or 30) that I would like to initialize, cluster and then pass to my various state cases.  Is there a way to define the variables in something like the type definition that you guys taught me how to do for enums that would make for easy maintenance?  Would you just create a type definition with the variables as controls with their default values set in the type definition...but then how would you cluster them so they would become one variable (All Variables  type def) when you brought them to the main program diagram?

 

Trying to be neater.

 

Thanks

 

Hummer 1

0 Kudos
Message 1 of 22
(3,352 Views)

Hi Hummer,

 

why don't you create the cluster as typedef with all those "variables" included?

And what's wrong with an init state in your state machine, where you cluster individual "variables"?

Message Edited by GerdW on 02-03-2010 06:04 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 22
(3,351 Views)

Thanks,

When I bring that cluster into the main diagram, it shows as a list of variable values ... I would rather it show as a reference of some kind to the single type def...how would I do that?

 

We're on the right track I think.

 

Hummer 1

0 Kudos
Message 3 of 22
(3,342 Views)

Hi!

 

I'm not sure if this will help you at all.  But your question is "How do you...".  Well, I would probably wrap these "variables" up in LVOOP class(es).  If you are familiar with type defs, an LVOOP class can be used in a similar way.  You define your cluster as a ctrl that is part of the Class, then make data accessors to all the items in your cluster.  LabVIEW makes data accessors automatically, which are great for trapping errors while writing back and forth from your cluster.

 

You can then drop your Class as an object constant in your block diagram (saves you the messy look of all those line items from your type-def in your block diagram).

 

I'm on quite a LVOOP kick with my last few projects.  Its totally worth the time to learn.  It has mostly replaced what I was using Action Engines for, and then some.

Message 4 of 22
(3,338 Views)

This looks interesting...how do you "unbundle" a class...I know how to do a cluster, but how do I get to the individual elements within the class to read and write them?

 

Thanksl.

 

Hummer1

 

0 Kudos
Message 5 of 22
(3,310 Views)

You HAVE to use data accessors.  Open your data cluster, righ-click on a control and select "Create Accessor".  From there you can select all of your fields and LabVIEW will automatically make "Read <field>.vi" and "Write <field>.vi" with dynamic dispatch and error terminals.

 

To me, this seemed like a hassel at first.  But this is actually a really good thing for troubleshooting and for creating single entrance points to read and write your data.  Its actually a really good thing, and NI was smart so they designed it that way.  The actual cluster data can only be unbundled by a child VI within the Class (because it is "private" data).

Message 6 of 22
(3,286 Views)

The Unbundle by Name and Bundle by name functions will not attach to the class box...in the help menu it says something about being members of the same ...  The main front panel and the class/ctrl are in the same project ... how do I get them to talk to each otehr?

 

Not Humming yet...

 

Hummer 1

0 Kudos
Message 7 of 22
(3,284 Views)

Hi Hummer1,

 

I like the LVOOP idea, but you can also just do it like this.  Since it's a typedef, you just open the custom control, make changes, and they propagate through...just like they did with the enum typedef.

 

Did I misunderstand your question?

 

d

Message 8 of 22
(3,279 Views)

So, by the accessor method...(made the read accessors ok)...you have to pull one accessor in for each variable you want to read and then another for each one you want to write?

 

Hummin now...

 

Hummer 1

 

0 Kudos
Message 9 of 22
(3,278 Views)

Thanks Dian...

 

when I tried it that way, when you pull the type def into the block diagram of the main program, the entire list of variables (without names) shows up in a cluster...What I was hoping for was a single icon...like a reference to the typedef that could then be attached to the wire leading to all my states that need variables...Can you do that somehow?

 

Thanks.

 

Hummer 1

0 Kudos
Message 10 of 22
(3,275 Views)