LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Static arrays

Solved!
Go to solution
Highlighted

I want to have a static array of Strings with fixed values.  I set the array up and saved it as a Data Type.  I can then drag it onto another VI and use its values which is great.  Then I shutdown NXG for the day, come back again, and the data type has lost all its values (its now an empty array.)  

 

Where I have used that data type on a VI, the values are remembered for that VI across NXG launches, but dropping a new instance of the data type just gives an empty one.

 

How do I create a data type with static, preset values that it keeps between launches of NXG?  

 

The only thing I can think of is an alternative approach which is to create a VI that builds and returns that array on demand but then I can't use it as a Data Type of course.

0 Kudos
Message 1 of 26
(318 Views)
Highlighted

Hi Andrew,

 

with classic LabVIEW a datatype only define the type of data, but not the values of that datatype. I guess NXG behaves the same way…

 

A "static arrays" as described by you sounds like an array constant (filled with your values) in the block diagram. Why don't you use an array constant when the data will stay always the same?

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 26
(308 Views)
Highlighted

I also haven't used NXG but in classic LV you would right click the control and say "Set value as default" which (I think?) would save them to the control.

 

Another option would be to use a Ring control, but I don't know exactly what it is you're trying to accomplish.

0 Kudos
Message 3 of 26
(293 Views)
Highlighted

I originally created it as a constant then used the 'Create a new G Type document' function to create the data type.  But it works as I described above - i.e. not between launches of NXG.  From what you say, that seems to be normal behaviour.

 

I've created a VI with the array on it as a constant and when I need to use it elsewhere in the application, I am copying it out of this VI.  That works across NXG launches and I think that's what you're suggesting?

 

I thought a data type would be a 'better' approach to this but I guess LabVIEW doesn't work like that.

0 Kudos
Message 4 of 26
(291 Views)
Highlighted

At least in classic LV, you can create a datatype and save it, but the default value isn't saved until you assign it manually (via right-click menu, Set Value As Default).

 

When you save a datatype it does NOT automatically assign the current value as default. In other words:

 

-Create new control file

-Add numeric indicator (standard default value is 0)

-Change control's value to 8

-Save file

 

That process will result in a control whose default value is 0, because you never changed the default, only the current value.

 

Try this:

 

-Create new control file

-Add numeric indicator (standard default value is 0)

-Change control's value to 8

-Right click, Set value as Default

-Save file

 

(See this article: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000wwkNCAQ&l=en-US)

 

0 Kudos
Message 5 of 26
(282 Views)
Highlighted

Unfortunately, when you set a value as default for the array, it means that every entry is that default value so that won't work unfortunately.  [EDITED this sentence to make it clearer.  Basically, Set As Default on an array applies to every entry in that array]

 

I just need to keep a list of standard values to use across my application to ensure that any selection has to come from a set which I know how to process.  As an example, think "I need to process some data but I don't know what type of data it will be in advance so I need to be told from a fixed set of possibilities that I can handle".

 

Anything that can hold the collection of values could be used, but a 1D array is the easiest for my purpose.

 

I had wanted to set that array up as a static array to just drop onto VIs as needed, but it looks like I need to set it up on its own VI (.gvi file) and copy from there to where I need it. 

0 Kudos
Message 6 of 26
(279 Views)
Highlighted

Instead of using an array for your G Type, you can use a cluster and convert it into an array wherever you need it.  You can then define exactly the default values as well as the number of elements.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 26
(268 Views)
Highlighted

This is how I would do it based on what I have read thus far:

 

I'd create a simple CSV file with the list of standard values that you need. Then, when your program first opens, read that CSV file into LabVIEW. If you need to add one, you can either add the new value on the fly or add it manually and then have a Callback VI setup to re-read the CSV file.

Message 8 of 26
(263 Views)
Highlighted

You could also define a tag to be used wherever you need it.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 26
(261 Views)
Highlighted

@Eric1977 wrote:

This is how I would do it based on what I have read thus far:

 

I'd create a simple CSV file with the list of standard values that you need. Then, when your program first opens, read that CSV file into LabVIEW. If you need to add one, you can either on the fly or add it manually and then have a Callback VI setup to re-read the CSV file.


To add to that idea, it might be easier to use config files since LV already has built-in VIs to read and write them.  To make an array, you can save the values as one key with the values comma separated, then read the key and use the delimited string to array function to get your array of values.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 10 of 26
(250 Views)