How to call one line at a time in LabVIEW read text file? - labview

I would like to read just one line of text at a time using "Read from text file" function. After the passing of this line I would like to move on to the next line after the rest of the program iterates once. When I change the "Read from text file" function to "Read lines", I can no longer put an indicator on the front panel for text. How can I iterate one line at a time? How can I put an indicator on the front panel to display which line of text was read?

This what you want:
Open/Create/Replace File (with inputs open and read-only)
— inside While Loop:
Read From Text File (with Read Lines)
End While Loop on error from Read From Text File
--After While Loop:
Close File
You can process the data in the While loop, or index it and process outside.

Read the Text file
Use for loop, and add the shift register to it
Through the input shift register terminal, wire the text file output (Initial data)
In Front panel, Right Click >> String >> Additional String Function >> Search/Split String
Wire the Initial data (from shift register) to the input string terminal and Provide the necessary search string/ Character (In my case, I have used line feed constant)
Search/Split String has two output terminals; Substring before the match and match +rest of the String
Trime the whitespace and wire the match +rest of the String o/p to the o/p shift register; Take the desired o/p from Substring before the match terminal
Set the tunnel mode of the desired string as indexing so that each line in the file is indexed to an element in the array.
Note: N value of the for loop's iteration terminal is equal to the no of lines in the file.

Related

Read and split line by line in text file

I am trying to read a text file from my applications resources. For each line in this text file I want to split the text before and after the comma.
Each line in txt file looks like this:
-125.325235,4845636
My issue is that the function loops and does not end constantly repeating the for each statement
For Each Line As String In My.Resources.CompanyBases
MsgBox(My.Resources.CompanyBases.Split(","c).First)
MsgBox(My.Resources.CompanyBases.Split(","c).Last)
Next
Firstly, don't ever get a resource over and over like that. Those properties are not "live". Every time you get the property, the resource has to be extracted from your assembly. If you need to use the value multiple times, get the property once and assign it to a variable, then use that variable over and over.
Secondly, you're not getting a file. The whole point of resources is that they are not distinct files but rather data compiled into your assembly. It's just a String like any other. How would you usually split a String on line breaks?
Finally, you have a For Each loop with a loop control variable Line, yet you never use that variable inside the loop. It should be Line that you're splitting inside the loop, not the resource property containing all the lines.
For Each line In My.Resources.CompanyBases.Split({Environment.NewLine}, StringSplitOptions.None)
Dim fields = line.Split(","c)
Debug.WriteLine(fields(0))
Debug.WriteLine(fields(1))
Next
Note that, if you're using .NET Core, Split will accept a String as well as a String array.

How to transform a text file with tab separated fields to a pipe separated fields in pentaho?

I have a situation where I want to transform a text file which has tab spaced fields like in the 'space-separated.png' below.
I want to transform this file by replacing tabs with pipes(|) like the 'pipe-separated.png' file below.
How can I do this in pentaho?
space-separated.png
pipe-separated.png
It can be achieved by a transformation with two steps.
Text file input (specify TAB as the separator in the content tab)
Text file output (specify | as the separator in the content tab)
Remember to click on 'Get Fields' option in both the steps. Not clicking on 'Get Fields' is what took me time.
If you don't want for any reason load as TEXT FILE OUTPUT step, you also can read the file text, without delimeter, so entire data will be in a row, use REPLACE IN STRING step, REGEX YES and search \t, replace for |. thats all.
all data in a field:
data view
Replace in string step:
Configuration
Preview result:
result with pipe

VBA Excel Reading text file from certain line number onward

say we have an external program, that writes a text file during a long calculation.
Now, I need to read that file in order to check the status of calculation (residuals values, stop on error etc).
The file has size of up to 1Mb. Since the program only adds new information to the end of the file, I dont want to reopen it and reread from the very beginning each time.
Is there a way to start reading the file from a specific line number (where I stopped last time)?
What happens to the file when it is opened in Excel for reading, and after that it is changed by the external program? EoF position shifts forward?
You can use the statement Seek [#]filenumber, position to move to a specific byte in a opened file. Just save the position in the file where you stopped with the function Seek( filenumber ) or with LOF( filennumber ) if you reached the EOF( filenumber ).

Finding occuramce of a string in a column in excel based text file

I am using vb.net to find the sum of occuramce of string in a particular column in text file(excel based) . The text file is not tab delimited, and it is separated column by column nicely, I only learnt how to read line by line using stream reader but I have no idea how to read only the last column of the line and summing up the specific string that I want. Any idea how to do it? Not nesseccary nid to provide me the code
If by "an Excel-based text file" you mean that the values are comma-separated, you can read it in line by line, like you already are doing using a stream, and then use Split to separate the line out into an array. Google "vb.net split" to learn how to do this.

document migration name extraction

I have a scenario and would like to see if anyone has any suggestions on how I should tackle it. Basically I have a directory full of files, document names consist of [Code]-[number]-[text]
CODE - A generic 3 letter code.
NUMBER - a number generally 4 - 5 digits in size.
TEXT - original document name (Before it was dumped).
CODE, NUMBER and TEXT are separated by a colon (-). Number always starts at the 5 character.
I would like to somehow scan that directory and extract the number from the filename, I would then like to compare that number to a field in a database (SQL query fairly straight forward, could also extract as raw text) If the number matches the number in the database I would like to separate those files.
If I need to clarify anything please ask. I wasn't sure if this site is appropriate for my query.
Open the root folder, click in the file explorer path (in open space off to the side so the whole path gets highlighted), type cmd and hit enter to open a command prompt from that folder location.
Type: dir /b /s > filelist.txt to get a list of all file names. You can exclude /s if you don't need/want to dig down into subfolders.
I'd paste that into excel, if you have 2013 you can just start typing the part you want to extract, after you type the full first line when you start typing the next line it will recognize the pattern and you can just hit enter to fill down.
Otherwise, use Data > Text to Columns and specify - as a delimiter.
Likewise you could just import the filelist, separate them in SQL using SUBSTRING() or similar. When you have your matching filenames you can just use some concatenation to build a COPY or MOVE .bat file, pretty easy in SQL or Excel.