I am making a project for my grade eleven computer science project. It is a program where you input your date of birth and it returns you the following:
Luckynumbers
What day of the week you were born on
your fortune
Everything works so far, but i am having a problem with the fortunes. I made many fortunes in a notepad file and I am using a sub to randomize which line and access them. My code looks as follows:
For some reason, it grabs only the first, or last lines of text. MY max is 290, my min is 1, any help is appreciated, thank you.
Luckynumbers
What day of the week you were born on
your fortune
Everything works so far, but i am having a problem with the fortunes. I made many fortunes in a notepad file and I am using a sub to randomize which line and access them. My code looks as follows:
Code:
Sub Fortunes()
Dim fortunes As New IO.FileStream("Fortunes.txt", FileMode.Open, FileAccess.Read)
Dim textFile As New IO.StreamReader(fortunes)
Dim lineOfText As String 'stores a line read from a file-
Dim randomLine As Integer
Randomize()
randomLine = max * Rnd() + 1
Do While (textFile.Peek > randomLine And textFile.Peek > -1) 'check for the end of file
lineOfText = textFile.ReadLine()
'display a line of text
Me.lblFortune.Text = lineOfText
Loop
textFile.Close()
End Sub 'Fortunes