LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data to array of strings in cluster by reference

Solved!
Go to solution

Im sorry but i cant follow you....

As i said i need to put in values in my array of stings at different places, for example index 2 and number 50.

I think i need a concrete example to understand. 

0 Kudos
Message 11 of 20
(155 Views)

I see now that i have to populate each index in numeric order to fill my array.

For example if i want to write 50 at index 2 i need first to write zero at index 0 and 1.

 

Is there a way to write 50 at index 2 without populate index 0 and 1 first?

0 Kudos
Message 12 of 20
(154 Views)

Hi tokar,

 


@tokar wrote:

Is there a way to write 50 at index 2 without populate index 0 and 1 first?


No.

In LabVIEW you cannot have an array that only has an element at index 2, but not for index 0 & 1…

 

(In string arrays you can write empty strings at index 0 and 1 before appending "50" at index 2. Is this the only reason to hold numeric values in a string array?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 13 of 20
(149 Views)

In LabVIEW you cannot have an array that only has an element at index 2, but not for index 0 & 1…

Answer: Ah ok

 

(In string arrays you can write empty strings at index 0 and 1 before appending "50" at index 2. Is this the only reason to hold numeric values in a string array?)

Answer: Perhaps it should be better to use an array of numeric values?

0 Kudos
Message 14 of 20
(146 Views)

Hi tokar,

 


@tokar wrote:

Perhaps it should be better to use an array of numeric values?


This depends on your requirements!

You didn't list all of them yet…

 

(Until now you just wrote about "how do I solve my problem?", but not about "what exactly is my problem?"…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 15 of 20
(141 Views)

@tokar wrote:

I see now that i have to populate each index in numeric order to fill my array.

For example if i want to write 50 at index 2 i need first to write zero at index 0 and 1.

 

Is there a way to write 50 at index 2 without populate index 0 and 1 first?


Kind of, reshape the array before. You will get default elements for new array elements. There is a node called reshape array that will grow or shrink an array.

 

place element at index while growing array if necessaryplace element at index while growing array if necessary

 

As Gerd said, arrays are always contiguous. There are no holes.

In other languages, you get a segmentation fault or a compiler error when writing to an array location that does not exist. (Or you modify the program in even more undesirable ways).

LabVIEW checks for out-of-bounds access and silently ignores the write. If you read from an out-of-bounds location, you get back the default value, which for numerics is zero, for strings an empty string.

Message 16 of 20
(122 Views)

People are helping you with your problem as requested, but in general you shouldn't use Front panel objects as data containers so the whole "reference front panel objects" is unnecessary/unwanted.

 

Indicators are just that, indicators. Keep the data in a cluster in a shift register.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 17 of 20
(113 Views)

Hi tokar

 

First you need to initialise the array using any empty string and choose a size appropriate for the number of entries expected. Then you can use replace subset to change the contents of any index. all unchanged entries will be blank and not 0 (zero). If you want zeros initialise the array with a string entry "0".

 

I can't provide a snippet or image, no LabVIEW where I am.

0 Kudos
Message 19 of 20
(55 Views)

Thank you all for all good information.

I solved my problem and got a better understanding of arrays now.

Cheers to all!

Message 20 of 20
(47 Views)