OK, I'm new to VB.Net so forgive me if this was covered else where and my search foo was week.
I am trying to read data from a text file which is updated regularly by another program. I only want to read the new data which will then be passed off to another device(ControlLogix 5000). The code I have thus far is below, this will read all the data, but once it reaches the end it stops. The second bit of code should send the data to the PLC. I am using VB.Net 2010

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim file_name As String = "C://Data/FileData.txt"
    Dim textline As String

    If System.IO.File.Exists(file_name) = True Then

        Dim objReader As New System.IO.StreamReader(file_name, True)

        Do While objReader.Peek <> -1
            textline = textline & objReader.ReadLine() & vbNewLine

        TextBox1.Text = textline

        MsgBox("File Does Not Exist")

    End If

End Sub

End Class

Dim asciidata As String
asciidata = textline

Edited by NavVet: Additional Info

6 Years
Discussion Span
Last Post by Mitja Bonca

You will have to store the data you have already read to a "temp" location.

That way every time you open the file again, you can compare to see if there is any new data, copying only the new data.


How your code can know which are "new" data?
Cant know at all.
What you can do, is to insert on the end of some text like END OF DATA",
so when you will insert new data, you will read from "END OF DATA" on.

This is my simple example, but this is how you have to start thinking. text file offers nothing specific to define something like you want, so its up to you how you will do it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.