I want to you Help me please

Category: visual studio visualiaztion

Question

Thanyathep on Thu, 01 Nov 2018 08:47:56


 I need the last line of txtfile that I randomly placed in txtbox. I tried it but it still does not work. Please help me and I want to save the last row of this data as txtfile too. Thank you.

Here this Code.

Imports System.IO

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        TextBox2.Text = ""

        Label1.ForeColor = Color.Green

        If Timer1.Enabled = True Then

            Label1.ForeColor = Color.Green

            Timer1.Start()

        Else

            Label1.Text = Label1.ForeColor = Color.Green

            Label1.Text = 20

            Timer1.Start()

        End If

    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Timer1.Start()

        Timer1.Interval = 10

        Dim objStream As StreamReader

        Dim sr As New System.IO.StreamReader("E:\aa\txtfile1.txt")

        Dim sr2 As New System.IO.StreamReader("E:\aa\txtfile1.txt")

        Dim i As Integer = 0

        Dim curline As Integer = 0

        Dim ran As Integer = 0

        Dim LineNumber As Integer = 0

        Do Until sr.EndOfStream = True

            sr.ReadLine()

            i += 1

        Loop

        sr.Dispose()

        sr.Close()

        '************  นับเวลาถอยหลัง แบบ count down ตั้งแต่ เลข10 จะเป็นสีแดง **********

        If Label1.Text = 10 Then

            Label1.ForeColor = Color.Red

            Label1.Text = Val(Label1.Text) - 1

            ' เมือนาฬิกา ถึงเลขศูนย์ นาฬิกา จะหยุด **********

        ElseIf Label1.Text = 0 Then

            Timer1.Enabled = False

            'MsgBox("Bingo!!")

        Else

            Label1.Text = Val(Label1.Text) - 1

        End If

        '******* แรนดอม ค่า ข้อมูลใน E:\aa\txtfile1.txt **************

        Randomize()

        ran = Rnd() * i

        Do Until ran = curline

            TextBox2.Text = sr2.ReadLine()

            curline += 1

        Loop

        sr2.Close()

        My.Computer.FileSystem.WriteAllText("E:\Textfiless.txt", "" & TextBox2.Text & " " & vbCrLf & "", True)

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

   

End Class

Replies

Andrey Belyakov on Thu, 01 Nov 2018 08:53:35


Hello,

Read your file line by line and put last row into property.