Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Visual Basic Programming

Visual Basic Programming Discussion forum for Visual Basic, an event driven programming language and associated development environment from Microsoft for its COM programming model.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-22-2008, 12:20 PM
wazofski wazofski is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 96
Rep Power: 2
wazofski is on a distinguished road
Default Need Help

I have a little box called: Box1. If you press the "START" Button the backcolor of the box will change in a random color of: Red, Blue, Yellow Or Green. But how can I do that? So it will random pick a color.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-22-2008, 01:18 PM
Xav's Avatar   
Xav Xav is offline
Guru
 
Join Date: Mar 2008
Location: London, England
Posts: 3,001
Last Blog:
Piano Exam
Rep Power: 26
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
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.
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-22-2008, 01:40 PM
wazofski wazofski is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 96
Rep Power: 2
wazofski is on a distinguished road
Default Re: Need Help

Thank you very much, I got it now and it works
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-22-2008, 01:44 PM
Xav's Avatar   
Xav Xav is offline
Guru
 
Join Date: Mar 2008
Location: London, England
Posts: 3,001
Last Blog:
Piano Exam
Rep Power: 26
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Need Help

Great! I'm glad to be of assistance. And if you thought I was helpful, click the little icon of the scales above my post on the right, to add to my reputation. Ta!
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-22-2008, 01:50 PM
wazofski wazofski is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 96
Rep Power: 2
wazofski is on a distinguished road
Default Re: Need Help

And how would I do that with instead of one box with 4 boxes?

EDIT:

NVM already have it :P

Last edited by wazofski; 04-22-2008 at 01:56 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-22-2008, 01:52 PM
Xav's Avatar   
Xav Xav is offline
Guru
 
Join Date: Mar 2008
Location: London, England
Posts: 3,001
Last Blog:
Piano Exam
Rep Power: 26
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Need Help

You mean every box has the same colour, or every box has its own randomised colour?

And also, consider that some boxes may get the same colour as each other. Does this matter to you, as if it does, we will need lots of extra code to make sure!
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-22-2008, 02:28 PM
wazofski wazofski is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 96
Rep Power: 2
wazofski is on a distinguished road
Default Re: Need Help

Erm another thing I need to know. I'm making the game: Mastermind with vb, but I got a few panels with colors and when you click it then the colors in the left panel will get that color you clicked. But I know how to set the colors, but when one of those boxes already has a color and you click it then the next box will get that color you clicked etc.

Few notes to screen:
- Top Panel is the random colors, the code you need to guess.
- Under that top panel, are the boxes that will get the color if you press a color at the right panel, to gues the code.


Last edited by wazofski; 04-22-2008 at 02:30 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-22-2008, 03:15 PM
Xav's Avatar   
Xav Xav is offline
Guru
 
Join Date: Mar 2008
Location: London, England
Posts: 3,001
Last Blog:
Piano Exam
Rep Power: 26
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Need Help

Use an If statement. If the box isn't white, move to the next one.
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-23-2008, 08:38 AM
wazofski wazofski is offline
Learning Programmer
 
Join Date: Feb 2008
Posts: 96
Rep Power: 2
wazofski is on a distinguished road
Default Re: Need Help

It doenst work with the IF statements, because when I press a color all the white boxes will be filled.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-23-2008, 03:21 PM
Xav's Avatar   
Xav Xav is offline
Guru
 
Join Date: Mar 2008
Location: London, England
Posts: 3,001
Last Blog:
Piano Exam
Rep Power: 26
Xav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to allXav is a name known to all
Send a message via MSN to Xav
Default Re: Need Help

What's it supposed to do, then?
__________________
Xav, the power of youth
Worship the Creator... not his creations
Web Site | Beta Site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 06:48 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads