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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.