Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to read file on timer tick ,i need to select file range from text box and then read those files. i am able read each file but,as i am ploting graph from those file i need a continues of each file ploting but the graph is directly showing last file graph when i add message box it is showing for each file and then going for next file. i want to the graph should be like movie on after another each file should roll on.

Thank you

What I have tried:

VB
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        For Each file1 As String In files
            Chart1.Show()
            Chart2.Show()
            Chart3.Show()
            Dim name As String = Path.GetFileNameWithoutExtension(file1)
            Dim fileNo As Integer



            If Integer.TryParse(name.Substring(1), fileNo) And fileNo >= TextBox1.Text AndAlso fileNo <= TextBox2.Text Then
                Dim f1 As String
                f1 = IO.File.ReadAllText("C:\Users\mks\Desktop\Newfolder\p" & fileNo & ".sp1")


                TextBox3.Text = file1
                Dim wFile, wFile1 As System.IO.FileStream
                Dim byteData(), byteData1(), byteDatayp(), byteDatayn(), byteDatabp(), byteDatabn(), byteDatarp1(), byteDatarn1(), byteDatayp1(), byteDatayn1(), byteDatabp1(), byteDatabn1() As Byte
                Dim rn, rp, yp, yn, bp, bn As String
                Dim r As String = Regex.Replace(f1.ToString, "[^1-9Z-]", "")
                '    Console.WriteLine(r)
                r = Regex.Replace(r.ToString, "[-]", "0")
                Dim elements() As String = Regex.Split(r, "Z")
                For Each element In elements

                Next

                rp = elements(0)
                rn = elements(1)
                yp = elements(2)
                yn = elements(3)
                bp = elements(4)
                bn = elements(5)

                byteData = Encoding.ASCII.GetBytes(rp)
                byteData1 = Encoding.ASCII.GetBytes(rn)
                byteDatayp = Encoding.ASCII.GetBytes(yp)
                byteDatayn = Encoding.ASCII.GetBytes(yn)
                byteDatabp = Encoding.ASCII.GetBytes(yp)
                byteDatabn = Encoding.ASCII.GetBytes(yn)

                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\ro.mod", "")
                wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\ro.mod", FileMode.Append)
                wFile.Write(byteData, 0, byteData.Length)
                wFile.Close()
                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\rs.mod", "")
                wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\rs.mod", FileMode.Append)
                wFile1.Write(byteData1, 0, byteData1.Length)
                wFile1.Close()
                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\yo.mod", "")
                wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\yo.mod", FileMode.Append)
                wFile.Write(byteDatayp, 0, byteDatayp.Length)
                wFile.Close()
                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\ys.mod", "")
                wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\ys.mod", FileMode.Append)
                wFile1.Write(byteDatayn, 0, byteDatayn.Length)
                wFile1.Close()
                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\bo.mod", "")
                wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\bo.mod", FileMode.Append)
                wFile.Write(byteDatabp, 0, byteDatabp.Length)
                wFile.Close()

                System.IO.File.WriteAllText("C:\Users\mks\Desktop\Newfolder\bs.mod", "")
                wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\bs.mod", FileMode.Append)
                wFile1.Write(byteDatabn, 0, byteDatabn.Length)
                wFile1.Close()
                File.Delete("C:\Users\mks\Desktop\Newfolder\ro1.mod")
                File.Delete("C:\Users\mks\Desktop\Newfolder\yo1.mod")
                File.Delete("C:\Users\mks\Desktop\Newfolder\bo1.mod")

                File.Delete("C:\Users\mks\Desktop\Newfolder\rs1.mod")
                File.Delete("C:\Users\mks\Desktop\Newfolder\ys1.mod")
                File.Delete("C:\Users\mks\Desktop\Newfolder\bs1.mod")
                For i As Integer = 0 To f1.Length - 1 Step 1
                    If i Mod 1 = 0 Then


                    End If
                    Try
                        Dim rp1 As String = i / 10 & " " & rp.Substring(i, 1) & Environment.NewLine

                        Dim rn1 As String = i / 10 & " -" & rn.Substring(i, 1) & Environment.NewLine
                        Dim yp1 As String = i / 10 & " " & yp.Substring(i, 1) & Environment.NewLine
                        Dim yn1 As String = i / 10 & " -" & yn.Substring(i, 1) & Environment.NewLine
                        Dim bp1 As String = i / 10 & " " & bp.Substring(i, 1) & Environment.NewLine
                        Dim bn1 As String = i / 10 & " -" & bn.Substring(i, 1) & Environment.NewLine

                        byteDatarp1 = Encoding.ASCII.GetBytes(rp1)
                        byteDatarn1 = Encoding.ASCII.GetBytes(rn1)
                        byteDatayp1 = Encoding.ASCII.GetBytes(yp1)
                        byteDatayn1 = Encoding.ASCII.GetBytes(yn1)
                        byteDatabp1 = Encoding.ASCII.GetBytes(bp1)
                        byteDatabn1 = Encoding.ASCII.GetBytes(bn1)

                        wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\ro1.mod", FileMode.Append)
                        wFile.Write(byteDatarp1, 0, byteDatarp1.Length)
                        wFile.Close()

                        wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\rs1.mod", FileMode.Append)
                        wFile1.Write(byteDatarn1, 0, byteDatarn1.Length)
                        wFile1.Close()
                        wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\yo1.mod", FileMode.Append)
                        wFile.Write(byteDatayp1, 0, byteDatayp1.Length)
                        wFile.Close()
                        wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\ys1.mod", FileMode.Append)
                        wFile1.Write(byteDatayn1, 0, byteDatayn1.Length)
                        wFile1.Close()
                        wFile = New FileStream("C:\Users\mks\Desktop\Newfolder\bo1.mod", FileMode.Append)
                        wFile.Write(byteDatabp1, 0, byteDatabp1.Length)
                        wFile.Close()
                        wFile1 = New FileStream("C:\Users\mks\Desktop\Newfolder\bs1.mod", FileMode.Append)
                        wFile1.Write(byteDatabn1, 0, byteDatabn1.Length)
                        wFile1.Close()






                    Catch ex As ArgumentOutOfRangeException
                        Exit For
                    Finally
                    End Try

                Next
                Chart1.ChartAreas(0).AxisX.ScaleView.Size = 100

                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\ro1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart1.Series(0).Points.AddXY(points(0), points(1))
                Next
                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\rs1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart1.Series(0).Points.AddXY(points(0), points(1))
                Next
                Chart2.ChartAreas(0).AxisX.ScaleView.Size = 100

                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\ro1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart2.Series(0).Points.AddXY(points(0), points(1))
                Next
                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\rs1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart2.Series(0).Points.AddXY(points(0), points(1))
                Next
                Chart3.ChartAreas(0).AxisX.ScaleView.Size = 100

                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\ro1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart3.Series(0).Points.AddXY(points(0), points(1))
                Next
                For Each line As String In IO.File.ReadAllLines("C:\Users\mks\Desktop\Newfolder\rs1.mod")
                    Dim points() As Double = Array.ConvertAll(line.Split(" "c), Function(s) CDbl(s))
                    Chart3.Series(0).Points.AddXY(points(0), points(1))
                Next
                MsgBox("FIlE HAS BEEN PROCEESED")

            End If
            Timer1.Stop()
        Next

    End Sub
    Private Sub CmdStart_Click_Click(sender As Object, e As EventArgs) Handles CmdStart_Click.Click


        Timer1.Interval = 10000
        Timer1.Start()


    End Sub
Posted
Updated 12-Feb-18 19:53pm
v2

1 solution

If I understood right what you want to do ...
You need to Clear the Points-Collection of each Series before you want to add new Points. If you don't do this you only enhance the allready assigned Points.
The method for this is :
VB
Chart1.Series(0).Points.Clear()
 
Share this answer
 
Comments
Member 13307200 13-Feb-18 2:08am    
Sir,
No with break point it will show the graph, but it is not possible to see files one after another without msgbox, after every file it will show graph and "the file has been processed" with msg box, i tried this your method it didnt worked.sir
Ralf Meier 13-Feb-18 3:08am    
I'm sorry ... so please explain exactly what you are trying to achieve ... What should exactly happen ...?
Member 13307200 13-Feb-18 4:00am    
sir sorry if u didnt got my problem,
I have folder with files with extension .sp1 . and each file is split into 6 files, these six files with name ro1,rs1,yo1,ys1,bo1 and bs1.
from these files i am plotting graph.
and i have to select range of files(.sp1 that i have done) and i need to plot graph for each file one after another. i am able to with breakpoint by means of message box. but with out message box also it should run like movie.means one after another without message box
Ralf Meier 13-Feb-18 6:18am    
I'm sorry also.
The part you described was the part I have got ...
What I understood was :
- you have a file (or some files) which contain the data for the curves.
- the file is created anywhere else and is updated cyclic - perhaps every minute
- you have a timer-called method which loads the file and display it's curve-data (perhaps also every minute).
- now if it works like this you can't add the new curve-data to the still existing from the chart - you have to replace the old data by the new data. This could be done if you first clear the Points-Collection of each Series before writing new data into it.

That was what I understood from your question. But this is not the thing you want to have - so to help you I need to understand the difference / what you want to have ...
Member 13307200 14-Feb-18 22:58pm    
Sir,
let me clear the things.
1. I am able to plot the graph from one file.
2. I am able to read multiple files and plot graph for each file.
3. Problem now to plot each file graph i am using for loop, i am unable to break the loop, to break after each file graph i am using msgbox,(u can find in code).
can it is possible to break without msgbox. thats why i used timer to break the loop on each timer tick. for every timer tick it should loop to next file.

I hope i cleared my question..
Any Help would be very helpfull for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900