Question pick a random?

digitalengineer09

New member
Joined
Mar 4, 2010
Messages
3
Programming Experience
Beginner
Hey Guys,
Im not so good at VB.NET , and ive been learning for about 3 months. I would really appreciate it if you guys would help me tackle this problem down.

Well , im helping a school run a Spelling Bee aimed at children in year 7. And to make it fair and unbiased i need an application that can choose randomise a word from the list box then transfer the string to the text box.

So basically something that can pick a random string from the listbox and show it in the textbox1.text property.

Once again , Thanks in advance. I would love it if you guys could help me with this problem. I cant seem to do it with the skills i currently have.

Bye,
Digital Engineer2010
 
Use the Random() class and its Random.Net(lowervalue_inclusive, uppervalue_exclusive) method to determine a list entry. Remove entry from listbox and store in textbox.
 
Man i still dont understand. If someone could help me i would really apreciate it . i have got a list box a button and a label in the gui part.
Thanks Guys!
 
Fixed

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As New Random

ListBox1.SelectedIndex = r.Next(0, ListBox1.Items.Count - 1)
TextBox1.Text = ListBox1.Text
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
 
You have to use ListBox1.Items.Count because the upper boundary is EXCLUSIVE.
i.e. r.next(1,6) will generate numbers from 1 to 5 and NOT up to 6
 
Back
Top