Page 1 of 1

Random number

Posted: Wed Aug 22, 2012 8:35 pm
by muttley1968
Hello I have a listbox full of numbers 1 through to 100 and I need to pick a number at random from there how would I do this and
then apply it to be the text of a button or label :P

I did try
Code: Select all
Dim ram as random 
label2.text = ram(1,listbox.items)
But it did not work :(

Re: Random number

Posted: Wed Aug 22, 2012 9:01 pm
by comathi
Oh, I think I see what you mean ;)

Try this:
Code: Select all
Dim ram As New Random()
Label2.Text = ListBox1.Items(ram.Next(0,ListBox1.Items.Count))
Enjoy :)

Re: Random number

Posted: Wed Aug 22, 2012 9:46 pm
by muttley1968
Worked thanks