LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling an array with values from a file

I'm trying to fill a one dimensional array with channel names that I
have stored in a .ini file. I was trying to add all of the names into
an array using a loop structure but it didn't seem to be working
properly. What's the best way to add elements to an array?
0 Kudos
Message 1 of 9
(4,911 Views)
I prefer to use a shift register and the "Build Array" function. Right click on build array and choose "Concatenate Inputs". Stretch the build funciton to 2 inputs and connect from the shift register on the left to the top input, from the new data to the second input and from the "Build Array" output to the shift register on the right.

If you know the size of the array beforehand, use an initialized array of the right size and just "Replace Array Subset". This is my preferred method (if I know the size of the array).

Have fun with it.

Rob
0 Kudos
Message 2 of 9
(4,911 Views)
Here's one way. You don't give any details on how you're doing iit but it's more effecient to use the auto-indexing of a For or While Loop output instead of the Build Array function.
0 Kudos
Message 3 of 9
(4,911 Views)
Thanks for the help. I ended up using this method and it worked perfectly. Thanks to everybody for helping a new user.
0 Kudos
Message 7 of 9
(4,911 Views)
It sounds like you have the right approach. Its hard to say what you are doing wrong without more details or a sample vi that demonstrates the problem.

What isn't working properly about it? Is it kinda working, but just not the exact desired results?

What type of loop are you using?

How are you reading the names from the ini?

What array functions, if any, are you using to build/populate the array?

The answers to these kind of questions would help us help you better.

Brian
0 Kudos
Message 4 of 9
(4,911 Views)
Find attached VI, maybe it's what you're looking for (it depends on how your ini file is formatted [it loads every line in a text file as a channel name]).

Hope this helps
0 Kudos
Message 5 of 9
(4,911 Views)
Mike,

I have extensive experience with this exact function.

Here is the best way to do it:

You know ahead of time what your array size is, because you are inputting the keys for your ini file that you are reading from, so, do an array size on the array of keys (you should create an array for your keys, and do your read in a for loop) and use that size to initialize an array of strings (or channel names?). Open your ini file, then, input your two arrays into the for loop. Read out the keys, and use the Replace Array Element function to input your values into the array at the appropriate index (index input wired to index of loop.) Then, after the loop, close your config file.

I hope this helps.

For additional functionality, I have created a tem
plate for reading from an ini file and storing the data in an unitialized shift register. This is very good design for storing configuration data for such things as manufacturing testing.

I will place a blank template for this in the designs discussion topic, so you can see exactly what I do with this.

Good luck
0 Kudos
Message 6 of 9
(4,911 Views)
michael_ashman@instron.com (Mike) wrote in message news:<38d808da.0201110703.56f458da@posting.google.com>...
> I'm trying to fill a one dimensional array with channel names that I
> have stored in a .ini file. I was trying to add all of the names into
> an array using a loop structure but it didn't seem to be working
> properly. What's the best way to add elements to an array?

You can also use the "Spreadsheet String to Array" function. Just
wire a 1D string array constant to the array type terminal and use
"%s" as the format specifier. Read the *.ini file and pass the string
to the function, no loops or shift registers needed.


sm
0 Kudos
Message 8 of 9
(4,911 Views)
Rob, What if you are building an array of strings? Thanks, Molly
0 Kudos
Message 9 of 9
(4,911 Views)