LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

get the last index of a string array

how to get the last index of a string array? the array size is always changes in certain situations

0 Kudos
Message 1 of 16
(605 Views)

Hi sinclair,

 


@sinclair15 wrote:

how to get the last index of a string array? the array size is always changes in certain situations


You want to know the ArraySize? Then why don't you determine the ArraySize?

 

(When you want to get the value of the last array element (of a 1D array) then use DeleteFromArray…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(599 Views)

Ok gerd thankyou, the problem has been resolved

0 Kudos
Message 3 of 16
(564 Views)

Hi sinclair,

 


@sinclair15 wrote:

the problem has been resolved


In which way did you solve the problem?

 

(You know in a public forum it's important to provide solutions to questions with some explanations. Others may benefit from your detailed answer - the same as you learned from asking…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 16
(558 Views)

@sinclair15 wrote:

how to get the last index of a string array? the array size is always changes in certain situations


For any array (not just an array of strings, what I assume you mean by "string array"), the index of the last element (I assume that's what you mean by "last index") is the array size minus one.

Message 5 of 16
(516 Views)

@GerdW wrote:

Hi sinclair,

 


@sinclair15 wrote:

how to get the last index of a string array? the array size is always changes in certain situations


You want to know the ArraySize? Then why don't you determine the ArraySize?

 

(When you want to get the value of the last array element (of a 1D array) then use DeleteFromArray…)


Note that when you don't wire the "index" input of "Delete from Array", it deletes the last element.

Message 6 of 16
(487 Views)

Obviously I am not versed in reading between the lines, but from the question, I assume ....

 

  • They are just interested in the index, not the value of the element (Delete from array does not give that information)
  • They want to keep the array intact. (Delete from array does not do that, so we need to branch the array first and continue with the intact version).

Of course the deeper question is why the array size is constantly changing and why they are interested in the "last index" (sic). Maybe they just want to determine the location where to append new data (e.g. using the misguided "insert into array"), something that is not necessary with the right primitive (i.e. "built array", possibly in concatenate mode). 😄

 

Sometimes the code can be rewritten to keep the array size constant and be less taxing on the memory manager, but for that we would need more detail about the requirements....

 

Message 7 of 16
(468 Views)

Hi,

 


@altenbach wrote:
  • They want to keep the array intact. (Delete from array does not do that, so we need to branch the array first and continue with the intact version).

I never mentioned to use the array output of DeleteFromArray, I just suggested to use the "deleted element" output of that node.

For the broader audience: DeleteFromArray can be used as a shortcut to "index the last element of an 1D array".

 

(I know that you know this, Christian. 🙂 )

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 16
(448 Views)

I sure hope that "delete from array" can eliminate the creation of the shortened array output if nothing is connected to it. I have never done any benchmarking.

 

(Back in the nineties, "delete from array" did not even exist and I still rarely use it) 😄

Message 9 of 16
(440 Views)

@altenbach wrote:

...

(Back in the nineties, "delete from array" did not even exist and I still rarely use it) 😄


You are right, and I made myself a polymorphic VI with that function. I called it "Pop Array Element" since I had some Perl- experience and there this task was named this way 😁

It also took me some time to get used to the "Delete Array Element"... 

 

Was Hänschen nicht lernt, lernt Hans nimmermehr! 😉

 

 

Greets, Dave
Message 10 of 16
(420 Views)