08-16-2016 06:12 AM
Hello everyone! I'm begginer in the LabView, so sorry for my easy question.
I want to oper the .txt file, read by rows it, find the numbers and write these numbers in the array.
For example -> .txt file looks like ->
voltage = 15
resistance = 3
current = 5
I want to get the array 3x1 ->
15
3
5
I;m trying to do it , but It doesnt work. Could u tell me where i have the mi.stake.
08-16-2016 06:28 AM
Try using "Read From Spreadsheet String/Read Delimited spreadsheet" based on LabVIEW Version. with = as delimiter
08-16-2016 06:28 AM
08-16-2016 06:28 AM
Before going to far..let me give you an introduction to LabVIEW Example Library.
From LabVIEW window you can go to <Menu>Help >> Find Example..
A window will open with lot of folders from there you will have to go to Search Tab and type a keyword for example that you want to find. If I type 'Read Text' it will give me a list of related examples from there you can double click and open the example and study it ..then make a copy of it and modify the copied VI.
08-16-2016 06:31 AM
Try this
08-16-2016 07:52 AM
Good idea, but i have got some questions:
1) My delimiter is Line Feed Constant, because as u show I want to get the array with the string elements (i mean line array). But u use the "=" as the delimiter, could u explain this moment ?
2) How did u create the "values" from the outputs of "Scan from string function" ?
08-16-2016 07:57 AM
I know that the use "read from spreadsheet file" is more profitable way. But now it's so important for me to find the mistake in my program, could u check it , I can't understand why do the elements of my array changing during the working my program but the in the end it's empy again (
08-16-2016 08:27 AM
In any Programming Language, strings are interesting data types, perhaps because they are so intimately tied in with how we (humans, using written language) communicate with machines (which use binary, often 8-bit bytes, as the fundamental building block). There's also the issue of representing such things as line breaks (different Operating Systems define "End of Line" using at least three different conventions).
LabVIEW has a number of functions that are designed to "take apart" strings and help you decipher them. The first place to start is when you input strings -- if you have a multi-line input, are you reading it as an "array of strings" (one element per line) or as a single multi-line string (which you then might want to break up into an array, where each line is a single string).
If we approach the interpretation of how to parse a single line such as "Temperature = 36", we (humans) generally look for, and exploit, patterns. Here, the obvious pattern is "a string identifier" (Temperature), "a separator" (the "=" sign), and "a numeric value" (the string "36"). With all of the String functions in LabVIEW, there are multiple ways to parse this string, but the easiest, in my opinion, is to use "Scan from String", where you use a Format string that notes what you expect the string to contain (Identifier, Separator, Numeric) and outputs corresponding to the things you identifed (here only Identifier and Numeric, as the Separator "matches" itself). So you drop down a Scan from String, wire your String to the input, and (after looking up in the Help what to use for the Format String, or by right-clicking the function and choosing Edit Format String and building the string), you create the Format String "%s=%f" (which means "some string followed by an equal sign followed by some floating point number"). When you do that, you'll notice that the function changes -- it now shows two outputs (labelled, in pink, "abc" for the string, and, in orange, "DBL" for the number). There will also be two input terminals for the default values of these outputs if nothing matches -- you can leave these blank if you want. Now wire "My Number" to the Dbl output and see what this does.
When you try this, you'll find "it doesn't work!", and will wonder, "why not?". Reading, you'll learn that %s matches strings up to "white space", so "Temperature=36" will match everything as a string. Aha, what you need to do is match a string consisting of anything except "=", then "=", then a number -- the correct Format String is %[^=]=%f ("%[^=]" means "match everything up to an equal").
Note while writing up this note, I had a blank VI open and was trying what I'm suggesting here. I'd forgotten that %s needed a blank to stop matching, so I got an error when I tried my own suggestion, above. But then I used LabVIEW Help, reminded myself how %s worked, and found the solution -- you can do this too!
Bob Schor
08-16-2016 08:29 AM
Hi Sep,
why do the elements of my array changing during the working my program but the in the end it's empy again (
THINK DATAFLOW!
Right now you don't think DATAFLOW. You have race conditions in there because of local variables/property nodes. You don't keep the values from previous iterations!
Your VI is overly complicated. Use the approaches shown before…
1) My delimiter is Line Feed Constant, because as u show I want to get the array with the string elements (i mean line array). But u use the "=" as the delimiter, could u explain this moment ?
The EOL is handled automatically by SpreadsheetStringToArray (read it's help!), the "=" is the delimiter between key and value in each line.
2) How did u create the "values" from the outputs of "Scan from string function" ?
It's a snippet, so you can evaluate it…
08-16-2016 08:41 AM
Hi Sep1ember
Hope GerdW Answered regarding your question delimiter
in addition to that your requiement is to extract only the values so to extract key values from key Names = can be a good way to use in a simple way