LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change data type "dynamically"

Hello,

 

I will try to explain my question, please tell me if it's not enough clear.

 

I read a text file wich describe me how to read datas in a product (their size, name, adress, type ...).

There is a lot of type (U8, U16, U32, STRING, DATE, I8, DBL ...).

 

The problem is I can't have an output in my VI for each type.

 

My goal is to make a VI with an output that adapt itself to the data type and I don't know how.

 

Maybe if it's possible to change the output declared dynamically depending on the type ... ?

An other idea is to create a cluster with all the data and just write in the good box with a condition structure but it's not the goal here.

 

Thank you in advance !!

 

0 Kudos
Message 1 of 5
(3,018 Views)

Solution 1: Use a polynomial VI. Use a single core subVI reading and extracting a specified column -- one and the same for each column, right? Use that subVI in each VI of the polynomial VI and specify the output according the wished parameter, e.g., column number or cell content structure.

0 Kudos
Message 2 of 5
(3,003 Views)

@Slate wrote:

Hello,

 

I will try to explain my question, please tell me if it's not enough clear.

 

I read a text file wich describe me how to read datas in a product (their size, name, adress, type ...).

There is a lot of type (U8, U16, U32, STRING, DATE, I8, DBL ...).

 

The problem is I can't have an output in my VI for each type.

 

My goal is to make a VI with an output that adapt itself to the data type and I don't know how.

 

Maybe if it's possible to change the output declared dynamically depending on the type ... ?

An other idea is to create a cluster with all the data and just write in the good box with a condition structure but it's not the goal here.

 

Thank you in advance !!

 


I would use either a variant or "flattened" string.  You would need to know how to unpack it "at the other end", so you might need an extra parameter.

0 Kudos
Message 3 of 5
(2,975 Views)

@Slate wrote:
[..]

I read a text file wich describe me how to read datas in a product (their size, name, adress, type ...).

There is a lot of type (U8, U16, U32, STRING, DATE, I8, DBL ...).

[...]

 


Question:

One file, one datatype?

Or is it mixed within a file?

 

If the file only consists ONE datatype (e.g. defined by some header information in the file), you could use a "header reader" to get the datatype. Using Plug-ins (more advanced technology), you can read/cast your data appropriately.

The major bottleneck is data you want to pass to the caller. The caller is rather static, so dynamic adaption on the datatype is not possible. But as already mentioned, passing all data as strings could be a good answer to leverage all datatypes to readable/usable data for the caller.

This very much depends on "what are you going to do with that data". Strings are "hard to handle" if you have to compute things. But they are easy to handle if it refers to display purposes only....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 5
(2,969 Views)

From your question (reading data from a text file), I'm assuming that (a) you can tell when one "piece of data ends and another begins" (for example, it might be a CSV file, with commas separating the fields, or there might be tabs or spaces between entries, or they might be all fixed width, e.g. 8 characters), and (b) you might know "in advance" the type of each piece of data.

 

If Assumption (a) is not true, then you may have real difficulties, so I'll assume it's true.  If Assumption (b) is also true, then you need a bunch of sub-VIs, "Read Integer", "Read Float", "Read String", maybe "Read Boolean".  Note that, depending on what you want to do with the data, you might not need a separate "Read I32", "Read I8", "Read U8" routine, as you could read everything as I32 and "coerce" it to the correct type when you go to use it.  Similarly, read all Floats as "Dbl".  I'm assuming that you "know" the appropriate "use" for each variable, such as "The Fifth Variable is the first name of the Account Holder", so you'd want to use "Read String" and output a String when processing the fifth "chunk of data" from the file.

 

If Assumption (b) is not true, you can still (sometimes) do a pretty good job reading/parsing the data.  I've done this for data I've read from an Excel Workbook.  What you do is apply some "rules", and hope that the data conforms to the rules.  Here's an algorithm to illustrate what I mean.

  1. Read in the data (as a string).
  2. Does it "conform to an integer number" (i.e. consist of possibly a leading + or - followed by only digits)?  Then it is an integer.
  3. Does it "conform to a float" by also having a single period?  Then it is a float.
  4. Otherwise it is a String.

Note you could ask about being "True" or "False" if you need to process Booleans.

 

BS

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