It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

How to "randomize"?

Moderator: dafunkymunky

How to "randomize"?

Postby Minecraftnate on Sun Feb 20, 2011 8:26 pm

How would I go about making a button that when pressed selects a random item from a long list of items?
Please explain in detail :).
User avatar
Minecraftnate
 
Posts: 1
Joined: Sun Feb 20, 2011 8:23 pm

Re: How to "randomize"?

Postby sanjon on Wed Feb 23, 2011 5:35 pm

I am not a professional so please excuse me if I'm wrong :) But you could give this a try:

Put this right under "Public Class Form1":
Code: Select all
Dim randomizer As New Random
Dim random As Integer
Dim list As New List(Of String) From {"first item", "second item", "etc."}

You can add or change the items in the list.

Then put this code where ever you want the random item from the list to be selected:
Code: Select all
random = randomizer.Next(0, 3)
MessageBox.Show(list(random))


In the line "random = randomizer.Next(0, 3)", you have to change the "3" to how many items are on the list. And you don't have to put the second line. Instead of putting the results in a Messagebox you can just display them on a label by writing "Label1.text = list(random)"

Hope this helped!
sanjon
 
Posts: 40
Joined: Sun Dec 05, 2010 6:20 pm


Who is online

Users browsing this forum: No registered users and 2 guests