In this article, I will show an example to set off a clause by a line for a text file in LabVIEW. The example for this article is implemented as a picture below.
There are simple description for that likes below.
- Read a text file.
- Make string arrays which is separated by line in a text file.
- Return the result which is included about a size of arrays and the number of line.
The key point for this is a second process. This shows the method to figure out the number of line in a text file. I think there is no difficult to understand about FILE IO because we use it to read a file many times. This code uses 'Read from text file" function. It is easy to use for you.
Let's look at the topic for the second process. This process uses "Spreadsheet String To Array" function in LabVIEW.
This function is a method to make a specific array from a string. Let's check the content using the picture above. In this picture, you can see the more details than my description.
There are 4 inputs and 1 output. Inputs are consisted of delimiter, format string, spreadsheet string, and array type. Output is just array for the result.
The main point in this function is a format string. This can decide the type of array for result. You can choose a type for string, double, or integer. In fact, this function is not important in my code, but this factor is important when you use it for a different situation.
The data-type doesn't matter this code just get the number of line in text file. If you want to process a text file more detail, you have to use a proper format string. Don't forget that string is %s, double is %f, and integer is %d.
If you want to get string array, you just modified this code likes below. You can make that is changed from double to string type.
Let's test this code. I made a sample for this test. This sample has 7 lines in a file which is named "about labview.txt" as below.
After executed this code, you can see the result below.
I think there are other options for that, but it is one of these option to get a result easily. I am going to attach the text file and vi in this blog. (The version of LabVIEW is 2013)
Attached files:
댓글 없음:
댓글 쓰기