LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of strings to cluster

Hello All,

 

I have an issue where I want to convert an array of strings into a cluster. Some of the elements in my array of strings contain numeric data. I want to convert those elements that are numeric to their correct representation and keep those elements in the array which are txt as string.

 

Array of strings contains:

 

Test1, 12.3456, Low, 12.4, 1.2, Hot,

 

I would like a cluster which has:

 

Test1 - String

12.3456 - Double

Low - String

 

How can I do this?

 

Thanks

 

 

0 Kudos
Message 1 of 5
(2,745 Views)

Use Index Array (exanded) to extract the individual parts and convert them with the appropriate function (as String to Fract/exp), then Bundle and you'll have your cluster. 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 5
(2,736 Views)

Note that the structure of the cluster must be known at edit time.  If your array always alternates between text and numeric, and if the size is always the same, then you can do something like this:

a2c.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 5
(2,715 Views)

@paul_cardinale wrote:

Note that the structure of the cluster must be known at edit time.  If your array always alternates between text and numeric, and if the size is always the same, then you can do something like this:

a2c.png


Oops.  I connected those wires from the DBLs to the bundler incorrectly.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 5
(2,712 Views)

If I understand correctly what you want to do, you want to create a Cluster whose element types (namely Dbl or String) are determined at run time (because you parse data that is a string consisting of an unspecified mix of Dbl or String "underlying data").  That means you don't know, until you parse the String, whether your cluster has (sequential) elements of "String, Dbl, String, Dbl" or "String, String, Dbl, String".

 

I encountered a situation where I had an Excel Worksheet whose first row had Element Names and the second row started the "data section".  Data types could be Integer, Dbl, String, or Boolean.  I wanted to make a Cluster that represented the Row, with element names taken from Row 1 and Types "deduced" from Row 2 that I could use to parse such a Spreadsheet as an Array of Clusters.  As the work evolved, we needed to expand the Spreadsheet (adding columns) and would therefore need to reconfigure the Cluster.  My "solution" was to learn enough LabVIEW Scripting to parse the "Master Spreadsheet" and create the Cluster Typedef that the rest of the Program would use.

 

I don't know how to do the dual task of creating a TypeDef for the Cluster (via scripting) and using the newly-created TypeDef to read and parse the data stream in a single routine.  If you have a few types of TypeDefs that you will encounter (for example, String, Dbl, String, Dbl and String, String, Dbl, String), you could define two Cluster Typedefs, and at Run Time, determine which was appropriate and use it.

 

The alternative is to keep everything as a String, but build a Cluster having elements "Data" and "Data Type", where "Data" was the parsed String (as a String) and "Data Type" was an Enum (String, Dbl, Int, Bool).  You read your data, parse it as an Array of "Flexible Type" (my name for this Cluster), and when you want to use it, you pass it to a function that returns the specific Type you've deduced you need.  I believe that the latest versions of LabVIEW have functions that can return multiple data types easily (I haven't had to do this, myself, so I'll leave this detail to others).

 

Bob Schor

0 Kudos
Message 5 of 5
(2,707 Views)