From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Initializing Column Size of Array

Solved!
Go to solution

Hello,

 

I have a comma delimited text file which is initialised into an array using the VI below.

 

The issue is that I have to place additional commas in order to make the array larger to provide additional empty columns.

 

For example:

 

Dog, Cat, Rabbit, , , , 

 

This script provides an array which is 7 columns wide. 

 

Is it possible for the initialization of the array to be formatted automatically with LabVIEW functions without having to use additional commas in the text file to be set to 7 commas?Capture.PNG

Would appreciate any feedback you may have

 

Many Thanks

0 Kudos
Message 1 of 12
(3,675 Views)

Use the Initialize Array VI to create an array of size 7 and replace a subset of that array with the data from your file.  Use the Read From Spreadsheet function to make that part of your code cleaner. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 12
(3,666 Views)

Or just read the array then use Insert Into Array to insert empty columns.

0 Kudos
Message 3 of 12
(3,664 Views)

Hi RavensFan, 

Did you mean like this? 

Capture.PNG

0 Kudos
Message 4 of 12
(3,659 Views)

Yes.  The only thing you might have to do is to make sure the index you are inserting into is either in the middle of the array, or is equal to the size of the array so that it will add the column to the end.  (i.e., you can't insert a column at column #7 if you only have 3 columns in the array.)  And remember that row and column indices start at 0.  So a 7 column array has columns at indices 0, 1, 2, 3, .... 6.

0 Kudos
Message 5 of 12
(3,650 Views)

Can you attach a simple text file and a simple script file. All this seems overly complicated.

0 Kudos
Message 6 of 12
(3,635 Views)

Try using the built-in function: Spreadsheet String to Array

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 12
(3,629 Views)
Solution
Accepted by topic author neunited

"Read from spreadsheet" file will give you as many columns as defined with the line containing the most commas. If you want more columns, do as suggested.

 

MoreColumns.png

 

("read from spreadsheet file (string)" replaces the "spreadsheet string to array" in the image code) 

Message 8 of 12
(3,624 Views)

Hi Altenbach, 

 

Thanks very much for illustrating that example, it was spot on for what I want to achieve. 

 

I attached another example VI for others to check out in case they have a similar problem. 

 

Many Thanks

0 Kudos
Message 9 of 12
(3,612 Views)

@neunited wrote:

 

I attached another example VI for others to check out in case they have a similar problem. 

 


That is not really useful unless you also give us a datafile. Still seems very convoluted.

0 Kudos
Message 10 of 12
(3,602 Views)