decrypt Posted June 23, 2004 Posted June 23, 2004 I want to make a program that has a file called "quotes.txt", with a different quote on every line. When the user clicks a button, it will get the amount of lines in the "quotes.txt", randomize a number in between 1 and the number of lines. And then go to the line of the number it just randomized. So for example: Number of lines in "quote.txt" = 10 Randomize a number between 1 and 10 number is 4 Go to line 4 of "quote.txt" Display line 4 of "quote.txt" in a textbox Is it possible to do all of this? I'm not sure how to do any of this. Could someone make up the code for this, because i'm not really good with reading from a text file... thanks... Quote
Mr60s Posted June 26, 2004 Posted June 26, 2004 Hi there, I don't really understand what your trying to do, but you could try something like this: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyLines As New ArrayList() Dim Total As Integer Dim Random As Integer Dim sreader As New IO.StreamReader("C:/quotes.txt") While Not sreader.Peek MyLines.Add(sreader.ReadLine) End While sreader.Close() Total = MyLines.Count Random = New System.Random().Next(0, Total) TextBox1.Text = MyLines(Random) MyLines.Clear() End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.