LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read array from .ini file

Solved!
Go to solution

I need to read in a short array of strings from a file. I don't want to add more files and wondered if there was an easy way to read an array of strings from an ini file. Since it will only be a dozen strings at most I suppose I could do it brute force:

 

[STRING ARRAY]

1= "string 1"

...

2="string 12"

 

 

Is there a mo betta way?

 

 

Thaniks,

 

jvh

0 Kudos
Message 1 of 13
(32,308 Views)

@jvh75021 wrote:

I need to read in a short array of strings from a file. I don't want to add more files and wondered if there was an easy way to read an array of strings from an ini file. Since it will only be a dozen strings at most I suppose I could do it brute force:

 

[STRING ARRAY]

1= "string 1"

...

2="string 12"

 

 

Is there a mo betta way?

 

 

Thaniks,

 

jvh


My brute force abproah is not that much different.

 

[Array_Name_Section]

Num_Items = 3

Array_Name_Item_0 =

...

 

I sued this approach in that method in my adaptive save restore Nugget as shown in this image below.

 

 

Have fun,

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 13
(32,306 Views)

I use the OpenG variant config. I never really cared how they store it, but I think it was comma separated.

 

Felix

0 Kudos
Message 3 of 13
(32,293 Views)
Solution
Accepted by topic author jvh75021

I simply put the entire string array into one key, comma delimted:

 

StringArray = xxxx,yyyy,zzzz

 

When I read the key, I add a return to it and treat it as a spreadsheet string.

 

Edit:

It's probably a good idea to put the strings in quotes, in case you have commas in your strings.

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 4 of 13
(32,286 Views)

I've just recently discovered the OpenG VIs for use with config files.

 

OpenG config file VIs

 

Here I used their "Write Section Cluster" VI to create a config file which showed me what syntax I needed for editing my config files that will work with their Read VIs:

 

Write to config file.png

Of course, the clusters are typedef'd, so all the elements inside this cluster constant have names.  Those names are used to automatically create the key names in the config file.  You can instantly create a very complex config file by simply connecting up almost any cluster you want to this Write VI (not sure what the limits are, though).

 

So, the simple, corresponding Read example VI is:

 

Init from config file.png

I've used both of these chunks of code in my current project, and I'm very impressed with how much easier it is to initialize huge amounts of arbitrarily complex data.  On a previous project, the "Init from Config File" VI spanned about 4 monitor widths to get all the data elements lined up and connected to all the "Read Key" VIs.  Now it can look like the code above every time.  Just change the cluster typedef.

 

- Brad

Message 5 of 13
(32,272 Views)

Brad, this palette is even more powerful.

Consider, you need to change one of your clusters, e.g. add a new measurement paramter. Just change the type-def and you are done! No need to modify your read config and your write config code, it's automagically adapted. Also using default values in the type-def will set these parameters to reasonable values when you load an old-format config file.

This really saves your day when you need to react on a customers feature wishes. 1/3 of places to change your code -> 1/3 less bugs introduced!

 

Felix

0 Kudos
Message 6 of 13
(32,267 Views)

Did a function search for openG but found nothing. Where is it located?

 

thanx,

jvh

 

0 Kudos
Message 7 of 13
(32,260 Views)

 


@billko wrote:

I simply put the entire string array into one key, comma delimted:

 

StringArray = xxxx,yyyy,zzzz

 

When I read the key, I add a return to it and treat it as a spreadsheet string.

 

Edit:

It's probably a good idea to put the strings in quotes, in case you have commas in your strings.


 

This works and suits my needs quickly. 

 

Thanks to everyone for posting. When I get caught up I will look into openG. Can openG be used with a file that already has the typical sections and keys?

 

Ben, like your idea too.

0 Kudos
Message 8 of 13
(32,256 Views)

On NI:

 

https://www.ni.com/de/support/downloads/tools-network/download.openg-libraries-for-labview.html

 

or:

 

http://wiki.openg.org/Main_Page

 

And the very fast way -> download VIPM (Community is free), you need it to install them anyhow:

 

http://jki.net/vipm

 

Felix

0 Kudos
Message 9 of 13
(32,250 Views)

@f. Schubert wrote:

...

Also using default values in the type-def will set these parameters ...

 

 

Felix


Hi Felix,

 

No I am not following you around. Smiley Tongue

 

Could you clarify the comment about the def of the type def?

 

Years ago I observed the the defaults defined in constants on the BD where wipped out when the typed was changed and defualt set in the control editor did not propogate to the BD instances.

 

Form that I have to assume your statement applies to defining the values in the BD.

 

Do I follow you correctly or did somthing change that I missed?

 

Your brother in wire, and student in OOP,

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 13
(32,209 Views)