So, in the previous post, we saw the difference between the AraryList and the array. The question is, "How do I convert an ArrayList into a LV array" - and quickly. It is reasonable to just iterate through the ArrayList and build up a LV array manually, if there are only a few elements in the list. But what if there are 1,000? 10,000? etc. etc.
I've created a LabVIEW 7.1 VI that shows how to do this. The first section is an artifact necessary to create an ArrayList with some data in it - you can ignore it since you should already have your ArrayList. But the next two sections show how to convert the ArrayList into an instance of an Array class, and then convert the Array class to a LV array.
So is there a nifty way to do this in reverse? E.g., can I take a LabVIEW array and stuff it into an ArrayList with a similar technique?
Posted by: Joe G. | September 22, 2005 at 12:53 PM
Yes and no. Using the other VI in that vi.lib library, To Object.vi, you can convert a LV array to a .NET array explicitly. What comes out of that VI, however, is System.Object.
To be able to pass it into the constructor of an ArrayList, you must first cast it to the ICollection interface. This is where the bug in LV 7 bites you - LV 7 doesn't support casting to interfaces in most cases. So you need to either create a helper assembly to do the cast for you or upgrade to Constellation when it ships.
So basically the answer is a qualified yes!
Posted by: Brian Tyler | September 22, 2005 at 02:33 PM
Is there a general solution to get the elements of a collection? Specifically, I want to use some classes in the System.XML namespace to get and replace some document elements. The method returns a nodeList. So, is this practical to do straight from LabVIEW or should I wrap the functionality in a DLL that returns an array to LabVIEW?
Mark
Posted by: Mark Smith | November 03, 2006 at 11:03 AM
I'm assuming you're talking about an XmlNodeList. The problem here is that it only supports the IEnumerable interface. This means converting it to an array in LabVIEW can be expensive if you have a large number of elements. You can always converts an enumerable into a LV array, one element at a time, but you can see the cost as it grows in size.
My recommendation to you and everyone else is
1. If you can write the .NET code, and it's easy to encapsulate into a handy routine that can be reused, then do that and return an array.
2. If you can't, or there would be dozens of these little .NET routines, consider not converting to a LV array. Perhaps you should provide accessor VIs, or create a LabVIEW class (8.20 and on feature).
Posted by: Brian Tyler | November 06, 2006 at 02:25 PM
Hey. New around here and figured that I should post and say hi.
Posted by: swasmawnvak | May 29, 2010 at 01:20 AM