Ai giúp mình cái Visual basic này với

sockscheap

Hero
Verified
Joined
Mar 5, 2012
Messages
1,349
Solutions
2
Reactions
916
MR
0.377
Telegram
Chat with me via Yahoo Messenger
Tình hình là mình có 1 file text nay mình muốn muốn cho Visual basic đọc từng dòng theo file text này khi nhấn vào 1 nút, tìm trên mạng sáng giờ toàn là đọc toàn bộ nội dung chứ không có đọc từng dòng. Có cái code này nó đọc từng dòng như nó lại random, mình muốn nó đọc theo thứ tự từ trên xuống, ai biết chỉ dùm hay fix lại dùm mình cái. Đây là đoạn code:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As New System.IO.StreamReader("C:\Users\VBTheory-PC\Desktop\New Text Document.txt")
Dim sr2 As New System.IO.StreamReader("C:\Users\VBTheory-PC\Desktop\New Text Document.txt")
Dim i As Integer = 0
Dim curline As Integer = 0
Dim ran As Integer = 0
Do Until sr.EndOfStream = True
sr.ReadLine()
i += 1
Loop
sr.Dispose()
sr.Close()
Randomize()
ran = Rnd() * i
Do Until ran = curline
TextBox1.Text = sr2.ReadLine()
curline += 1
Loop
End Sub
End Class
 
vb hok rành lắm, search thấy cái code này thớt thử xem
Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
Dim TextLine As String
If System.IO.File.Exists( FILE_NAME ) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Do While objReader.Peek() <> -1
TextLine = TextLine & objReader.ReadLine() & vbNewLine
Loop
Textbox1.Text = TextLine
Else
MsgBox("File Does Not Exist")

mà sao lại có dòng
Randomize()
ran = Rnd() * i
mình nghĩ
Do Until curline=i
TextBox1.Text = sr2.ReadLine()
curline += 1
Loop
là được rồi thêm biến ran chi ?
 
3 năm rồi ko đụng VB vì nó viết ko sướng tay, lục lọi chút trong bộ nhớ xem nào
-------------------------------------------------------------------------------------------
Dim line As String
' Read the file and display it LINE BY LINE
Dim file As New System.IO.StreamReader("c:\test.txt")
While (InlineAssignHelper(line, file.ReadLine())) IsNot Nothing
Console.WriteLine(line)
End While
' Close file
file.Close()
' Suspend the screen.
Console.ReadLine()
 
3 năm rồi ko đụng VB vì nó viết ko sướng tay, lục lọi chút trong bộ nhớ xem nào
-------------------------------------------------------------------------------------------
Dim line As String
' Read the file and display it LINE BY LINE
Dim file As New System.IO.StreamReader("c:\test.txt")
While (InlineAssignHelper(line, file.ReadLine())) IsNot Nothing
Console.WriteLine(line)
End While
' Close file
file.Close()
' Suspend the screen.
Console.ReadLine()
Đã thử rùi mà không được pro ơi, VB viết ko sướng tay, vậy chắc là C# rồi, mà C# nó khó kinh lắm
 

Announcements

Today's birthdays

Forum statistics

Threads
418,818
Messages
7,076,738
Members
170,889
Latest member
sukemsk
Back
Top Bottom