Thread: Need Help
View Single Post
  #2 (permalink)  
Old 04-22-2008, 01:18 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 5,030
Last Blog:
Web slideshow in JavaS...
Rep Power: 43
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: Need Help

First, load up the START button's click event handler. Then, use System.Random.

First, you create a new random object:

Code:
Dim r As New System.Random(Now.Millisecond)
Then, to choose a random number between 1 and 4:

Code:
Dim i As Integer = r.Next(1,5)
Note we use '5' and not '4'. This is because the upper bound is exclusive, so it means "everything below the upper number. This does not apply to the lower number.

Then, use a select case statement:

Code:
Select Case i

  Case 1
    Box1.BackColor = Color.Red
  End Case

  Case 2
    Box1.BackColor = Color.Blue
  End Case

Case 3
    Box1.BackColor = Color.Yellow
  End Case

  Case 4
    Box1.BackColor = Color.Green
  End Case

End Select
I think that's how you do it in VB. I'm more used to C#, so it might not be exactly how you do Select Case statements.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Web Site | Beta Site
Reply With Quote