我想在VB.NET中读取计时器上的文件 [英] I want read files on timer tick in VB.NET

查看:50
本文介绍了我想在VB.NET中读取计时器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在计时器刻度上读取文件,我需要从文本框中选择文件范围,然后读取这些文件。我能够读取每个文件,但是,因为我正在从这些文件中绘制图形,我需要继续每个文件绘图但是图形直接显示最后的文件图形,当我添加消息框时,它显示每个文件然后转到下一个文件。我想图表应该像电影一样接着每个文件应该滚动。



谢谢



我尝试了什么:



 私人  Sub  Timer1_Tick(发件人作为 对象,e  As  EventArgs)句柄 Timer1.Tick 
对于 每个 file1 作为 String 文件中
Chart1.Show()
Chart2.Show()
Chart3.Show()
Dim name As String = Path.GetFileNameWithoutExtension (file1)
Dim fileNo As 整数



如果 整数 .TryParse(name.Substring( 1 ),fileNo) fileNo> = TextBox1.Text AndAlso fileNo< = TextBox2.Text 然后
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()作为 字节
Dim rn,rp,yp,yn,bp,bn As String
Dim r 作为 字符串 =正则表达式.Replace(f1.ToString, [^ 1-9Z - ]
' Console.WriteLine (r)
r = Regex.Replace(r.ToString, [ - ] 0
Dim elements() As String = Regex.Split(r, Z
对于 每个元素元素

下一步

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 = 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 = FileStream( C:\ Users \mks \Desktop \Newfolder \rs.mod,FileMode.Append)
wFile1.Write(byteData1,< span class =code-digit> 0 ,byteData1.Length)
wFile1.Close()
System.IO.File.WriteAllText( C:\ Users \mks \Desktop \ Newfolder\yo .mod
wFile = 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 = 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 = 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 = Fil eStream( 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
对于 i As 整数 = 0 f1.Length - 1 步骤 1
如果 i Mod 1 = 0 然后


结束 如果
尝试
Dim rp1 作为 字符串 = i / 10 & & rp.Substring(i, 1 )& Environment.NewLine

Dim rn1 As 字符串 = i / 10 & - & r.s.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 = FileStream( C:\ Users \ mks\Desktop\Newfolder\ro1.mod,FileMode.Append)
wFile.Write(byteDatarp1, 0 ,byteDatarp1。长度)
wFile.Close()

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






Catch ex As ArgumentOutOfRangeException
退出 对于
最后
结束 尝试

下一步
Chart1.ChartAreas( 0 )。AxisX.ScaleView.Size = 100

对于 每个作为 字符串 IO.File.ReadAllLines( C:\ Users \mks \Desktop\Newfolder\ro1.mod
Dim points() As Double = Array.ConvertAll(line .Split( c),功能(s) CDbl (s))
Chart1.Series( 0 )。积分。 AddXY(points( 0 ),points( 1 ))
下一步
对于 每个作为 字符串 IO.File.ReadAllLines( C:\ Users \mks \Desktop\Newfolder\rs1.mod
< span class =code-keyword> Dim points() As Double = Array。 ConvertAll(line.Split( c),功能(s) CDbl (s) )
Chart1.Series( 0 )。Points.AddXY(points( 0 ),分( 1 ))
下一步
Chart2.ChartAreas( 0 )。AxisX.ScaleView.Size = 100

对于 每个作为 字符串 IO.File.ReadAllLines( C: \ Users\mks\Desktop\Newfolder\ro1.mod
Dim points() As Doub le = Array.ConvertAll(line.Split( c),函数(s) CDbl (s))
Chart2.Series( 0 )。Points.AddXY(points( 0 ),points( 1 ) )
下一步
对于 每个 line 作为 字符串 IO.File.ReadAllLines( C:\ Users \mks \Desktop\Newfolder\rs1.mod
Dim points() As Double = Array.ConvertAll(line.Split( c),功能(s) CDbl (s))
Chart2.Series( 0 )。Points.AddXY(points( 0 ),points( 1 ))
下一步
Chart3.ChartAreas( 0 )。AxisX.ScaleView.Size = 100

对于 每个 As 字符串 IO.File.ReadAllLines( C:\ Users \mks \Desktop\Newfolder\ro1.mod
Dim points() As Double = Array.ConvertAll(line.Split( c),功能(s) CDbl (s))
Chart3 .Series( 0 )。Points.AddXY(points( 0 ),points( 1 ))
下一步
对于 每个作为 字符串 IO.File.ReadAllLines( C:\ Users \ mks \Desktop\Newfolder\rs1.mod
Dim points() As Double = Array.Co nvertAll(line.Split( c),功能(s) CDbl (s))
Chart3.Series( 0 ) .Points.AddXY(points( 0 ),points( 1 ))
下一步
MsgBox( 已经过了

结束 如果
Timer1。停止()
下一步

结束 Sub
私有 Sub CmdStart_Click_Click(发件人作为 Object ,e As EventArgs) Handles CmdStart_Click。点击


Timer1.Interval = 10000
Timer1.Start()


结束 Sub

解决方案

如果我理解你想要做什么......

你需要在添加新积分之前清除每个系列的积分。如果你不这样做,你只增强已经分配的点数。

这个方法是:

 Chart1.Series( 0 )。Points.Clear()


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:

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

解决方案

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 :

Chart1.Series(0).Points.Clear()


这篇关于我想在VB.NET中读取计时器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆