我正在嘗試製作一個讀取大文檔(例如聖經)的程序,並輸出多個隨機線。我可以得到它輸出一個隨機線,但沒有其他人。從大文檔輸出到文本框的隨機線
最終目標是有一個用戶輸入來確定顯示的行數。
這裏是我的代碼:
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 –