0

Hi clever people,

I need some help making a VB application which chooses a random line for a file, sets it as the value of a Label (word) and also adds it to a ListBox (list) when a Button (nextbut) is pressed. I also want it to keep going.

Button; Text: Next
Name: nextbut

Label; Name: word

Listbox;Name: list

What i need it to do is to load a line from a file ("C:\words.txt" for example) and set it as the value f the label. The lines are different lenghts.

Any hwlp would be highly appreciated

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Reverend Jim
0

You can get the list of words into an array by

Dim words() As String = Replace(My.Computer.FileSystem.ReadAllText(filename), vbLf, "").Split(vbCr)

To generate a random index for words you can call

Private Function Random(ByVal lo, ByVal hi)

    'returns a random integer in the range [lo,hi]

    Random = lo + CInt(Rnd() * (hi - lo))

End Function

Just pass it lo=0 and hi=ubound(words). Make sure you call Randomize() when the form loads to avoid generating the same string of random numbers each run.

Edited by Reverend Jim: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.