From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Reference to array element

I have a subVI that takes an array reference and modifies the array.  The array contains an array of strings.  I would like to use the same subVI to modify a single string.  Is there a way to create an array reference to a string.  I have seen the build array control; however, I can't pass the results of that in. 
 
An alternative that I know will work is to create a temporary array and pass that it.  However, this would complicate my VI since I extract many strings. 
 
In C, this could be done by passing in the address of the string and passing in the size of the array (size 1). 
 
   char name[80];
   int size = 1;
 
   callSubfunction(name, size);
 
Thanks
 
Will
0 Kudos
Message 1 of 15
(39,597 Views)

Here's a nicer screenshot.

 

 

0 Kudos
Message 2 of 15
(39,583 Views)
You have an array of strings. 
You are passing the reference of that array to the readXMLValue.vi.
 
Curiosity question: Why are you using Local Variables to index the array (especially a double), and for the string array itself?
You're then passing one element to the vi.  But you have access to all the elements within the vi because of the reference.
 
There's no need to create a temporary array, or variables of or anything like that..  Let's focus on what you want to do..
 
If I understand correctly, you want to extract an element (string) from the string array, change it and then replace the original one in the array.
Do you want to do that inside the readXMLValue.vi?  or outside it.  Either way, the step is easy.
 
One thing to mention is that in Labview, the wire is the variable, so it is much better to wire values and NOT using Locals and avoid unnecessary references.
 
Do you also want the ability to search the array for the element?  Or is the string you would be searching for part of an element?
 
Example
 
StingArray [ me, you, Labview, fun, learn]
 
and if you search for fun, you'd get an index of 3.  You can the use that index to replace the element.
 
R
0 Kudos
Message 3 of 15
(39,581 Views)

Hi, Will,

Not fully understand what you need, but you can get reference to array element by according property node:

but you will be not able to get array of refences of the elemenths, because you have only one.

For example: this code looks the same but will not work:

Andrey.

 

Message 4 of 15
(39,569 Views)
First, do you really need to do this by reference? Can't you simply pass the
array into and outoff the subvi, and update the returned value with a local?
Much better, but you might have your reasons...

You can make the VI handle both array references and string references. The
input reference type should be changed to Control, so both types of
references can connect to it. In the VI, you need to check if you can cast
the reference to a string or array, or use the classname to deside what it
is you've wired. Wire the classname to a case, cast the control ref to it's
type, get the value and do to it what you want...

Regards,

Wiebe.


0 Kudos
Message 5 of 15
(39,564 Views)

If the array processing has to be done in a sub-vi, then why not wire the string array directly to the corresponding string array control in the connector pane?  no need for references, no need for locals..

Also, that's why I asked if a sub-vi is even needed. 

R

0 Kudos
Message 6 of 15
(39,531 Views)
> First, do you really need to do this by reference? Can't you simply pass the
> array into and outoff the subvi, and update the returned value with a local?
> Much better, but you might have your reasons...
 
The function adds onto the array.  It could be done your way also, but other code would need to be modified.
 
 
0 Kudos
Message 7 of 15
(39,527 Views)


WilliamLee wrote:
     I would like to use the same subVI to modify a single string.  Is there a way to create an array reference to a string. 

   The function adds onto the array.  It could be done your way also, but other code would need to be modified.


Does the sub-vi already allos to modify a single element?  or do you need to modify it?

Did you write the sub-vi or did you inherit it?  Does it appear in other code?

Without considering thew sub-vi, can you describe what you would like to do with the string array, the element and the string that you'd like to change?

R

0 Kudos
Message 8 of 15
(39,516 Views)

This "Index Vals" approach ONLY works if there is only one array element visibly on the Array control / Indicator.

 

Otherwise clicking on any array element besides the first one before running the VI will return false values.

 

Shane.

0 Kudos
Message 9 of 15
(39,112 Views)

I tryed to get the reference of my arrays elements, but if i want to set the "IndexVal" property of my "(strict)array reference" i get the

 

Error:

"Error 1082 occurred at Property Node (arg 2) in recursiveTypecastToU08.vi:2->Conv_ArrU08ToCluster.vi->conv_ClusterToCluster.vi->DUT_Battery_SetShipmentmode.vi
Possible reason(s):
LabVIEW:  Operation not valid for strict type definition instance.
Property Name: Index Values"

 

But WHY?

 

The reference:

Class name: Array
Control label: Data
Refnum (in hex): 0xC2A00088
Owning VI: Test.vi

 

 Get a "MoreSpecific Class"-cast to array-class and then the error apears.

If i use it directly there is no "IndexValues"-conector.

 

Thanks for your help.

0 Kudos
Message 10 of 15
(38,620 Views)