Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...