我正在尝试制作一个读取大文档(例如圣经)的程序,并输出多个随机线。我可以得到它输出一个随机线,但没有其他人。从大文档输出到文本框的随机线
最终目标是有一个用户输入来确定显示的行数。
这里是我的代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Dim howmanylines As Integer
' howmanylines = InputBox("how many lines for paragrpah", "xd",,,)
'Dim count As Integer = 0
' Do Until count = howmanylines
Dim sr As New System.IO.StreamReader("C:\Users\Dumpster Faggot\Desktop\bible.doc")
Dim sr2 As New System.IO.StreamReader("C:\Users\Dumpster Faggot\Desktop\bible.doc")
Dim sr3 As New System.IO.StreamReader("C:\Users\Dumpster Faggot\Desktop\bible.doc")
Dim xd As Integer = 0
Dim curline As Integer = 0
Dim random As Integer = 0
Do Until sr.EndOfStream = True
sr.ReadLine()
xd = xd + 1
Loop
sr.Dispose()
sr.Close()
Randomize()
random = Rnd() * xd
Do Until curline = random
TextBox1.Text = sr2.ReadLine
' curline = curline + 1
Randomize()
random = Rnd() * xd
TextBox1.Text = sr3.ReadLine
curline = curline + 1
' count = count + 1
Loop
End Sub
End Class
你只有一个文本框来显示结果吗?您正在覆盖每个循环的TextBox1.Text ...您需要一个列表或任何种类的集合 –
是的,我只有一个文本框,但我将其更改为多行将不工作? – Nosnhoj
不,你不是追加内容,而是覆盖它。试试这个:TextBox1.Text + = sr3.ReadLine –