LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

converting string from file to array

Solved!
Go to solution

I'm new to LabVIEW and have been thrown into the middle of a project, so I need to get some code working fast! Can someone help me understand why the VI I've attached isn't working? I want to have a text file that contains a list of integers that will be used to reference particular elements in arrays within my program. I tried to follow an example I found, but the output that should be an array is coming out as a scaler. Any help would be super appreciated! Thanks!

Download All
0 Kudos
Message 1 of 9
(4,929 Views)

Hi

    Can you post this code in LV8.6 or 2009?

Thanks

Sivabalan.V

0 Kudos
Message 2 of 9
(4,914 Views)

STR2Array.JPG

 

Hi 

  Use Line feed constant. I think it is work.

 

Thanks,

Sivabalan.V

0 Kudos
Message 3 of 9
(4,905 Views)

Thanks for the help, Sivabalan! When I implement this I'm getting the first number, but not all the numbers in the text file into an array of numbers (a problem I ran into with other methods I tried). Do I need to format the numbers within the text file a certain way such that they're all read in as separate elements within an array?

 

Thanks!

Christina

0 Kudos
Message 4 of 9
(4,889 Views)

Putting each number on a new line in the text file should display them properly in the array, also whilst you're showing them in I32 remember that your numbers should exceed 9 digits!

Otherwise you will not get the number you expected.

 

Hope this helped,

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
0 Kudos
Message 5 of 9
(4,885 Views)

Turns out it's not a problem with how the numbers are formatted in the text file: if I try to connect the output of "decimal string to number" to the array input for an "index array" block I'm told that I've "connected a scalar type to an array of that type," which is the same error I was originally getting (see my attached original file)...

0 Kudos
Message 6 of 9
(4,879 Views)
Solution
Accepted by topic author Aurora8283

First, let's explain the reason for your error: The reason why it's happening is that you're trying to do two different things at the same time. You're auto-indexing the array and you're trying to index the array inside the loop. When you wire an array to a for loop it auto-indexes the loop. Meaning LabVIEW knows how many times to run the loop - there is no need to wire to the N terminal. Also, the wire inside the loop will be an instance of the element of the array, not the array. So, the wire inside the loop is a scalar. Thus, the reason for the broken wire - you can't index a scalar.

 

Also, I'm not sure what you're trying to do with the indexing of the one element of the cluster. The cluster is empty, so there's nothing to index. Presumably the file is there to tell you which elements to pull out from the "Amp2" array from the cluster. If so, remember that auto-indexing works both ways. If you connect an "outbound" wire to the edge of a loop it auto-indexed there as well, meaning the output will be an array.

 

Please read the LabVIEW Help on auto-indexing.

 

 

Now, given all of that, here is what your code should look like:

 

Note the use of the Read From Spreadsheet File VI. It makes your life easier.

 

Message 7 of 9
(4,871 Views)

Thank you so much for taking the time to explain that to me! I had no clue what auto indexing was!

0 Kudos
Message 8 of 9
(4,858 Views)

It sounds like you did not go through the LabVIEW tutorials: To learn more about LabVIEW it is recommended that you go through the introduction material, tutorial(s), and other material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

0 Kudos
Message 9 of 9
(4,855 Views)