Random number

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Random number
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 :(
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Random number
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 :)
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: Random number
muttley1968
Worked thanks
3 posts Page 1 of 1
Return to “Coding Help & Support”