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: 

How can insert different data types into array ?

Solved!
Go to solution

Hi,
how i can insert different data types into array, (e.g. numeric and string) in the same index of an array.

example:
index0    car 10 green

index1    11 car red
index2    car blue 12

where car green, car red and car blue as string and 10, 11 and 12 as numeric.
then i will extract 10, 11 and 12 to a numeric array

and, car green, car red, car blue to a string array 

Help!

0 Kudos
Message 1 of 6
(2,898 Views)

All elements on an array must have the same datatype.

 

  1. You can format the numer as a string and use an array of strings.
  2. You could also create an array of clusters, where each element is a cluster of a string and a numeric, for example.

Please tell us a little more what you are actually trying to achieve with all this.

0 Kudos
Message 2 of 6
(2,894 Views)

An Array is of a single data type and must always be so.  You can not do as you ask but there are ways to accomplish something similar.  For instance, the array can be strings and simply convert the numeric portion to a numeric data type later as you construct the separate array.

 

So you would have "car red 10" and then later extract the "10" and convert it to a number.

 

Another option, is to use an array of Clusters.  Clusters group objects of any data type together but they must all be of the same design (data types must always be in the same order).  The data you provided seems to indicate the order of the number and car color will be random ( i have absolutely no idea why you want this as it only causes additional problems).

0 Kudos
Message 3 of 6
(2,892 Views)

"So you would have "car red 10" and then later extract the "10" and convert it to a number."

this way how it can be done ?

0 Kudos
Message 4 of 6
(2,886 Views)
Solution
Accepted by topic author nassarzakaria

Use "Scan from String" like in the attached image.  This will extract both the number and color which you can add to arrays later.

Message 5 of 6
(2,877 Views)

thanx alot pjr1121 🙂

0 Kudos
Message 6 of 6
(2,830 Views)