Reply

Join Date: Jan 2007
Posts: 28
Reputation: KalebG is an unknown quantity at this point 
Solved Threads: 0
KalebG's Avatar
KalebG KalebG is offline Offline
Light Poster

Random color?

 
0
  #1
Feb 9th, 2007
ME and a freind of mine have a vB class. We are using the schools outdated microsoft visual basic 2003. We in are spare time are trying to make a "Siezure" program. The point of this program is to simply have the user click a button and the background begin to flash Random colors. We could easily use a timer with a set of colors but we want to use random colors so they are unpredictable. We have tried multiple sets of code but can't seem to get anything to work. Could anyone tell me the code for making the background color of a forum flash with random colors?
Boo.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Random color?

 
0
  #2
Feb 10th, 2007
Generate a random number from 0 thru 16777215 (hex FFFFFF) and load the background color property.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: muthulakshmil is an unknown quantity at this point 
Solved Threads: 1
muthulakshmil muthulakshmil is offline Offline
Newbie Poster

Re: Random color?

 
0
  #3
Feb 12th, 2007
Originally Posted by KalebG View Post
ME and a freind of mine have a vB class. We are using the schools outdated microsoft visual basic 2003. We in are spare time are trying to make a "Siezure" program. The point of this program is to simply have the user click a button and the background begin to flash Random colors. We could easily use a timer with a set of colors but we want to use random colors so they are unpredictable. We have tried multiple sets of code but can't seem to get anything to work. Could anyone tell me the code for making the background color of a forum flash with random colors?

RGB color value is 0 to 255. so use the for loop and generate number from 0 to 255. and then set the value of for loop to RGB value.

otherwise generate random number

Randomize()

int r=rnd()*10
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 8
Reputation: waynewilson1 is an unknown quantity at this point 
Solved Threads: 0
waynewilson1's Avatar
waynewilson1 waynewilson1 is offline Offline
Newbie Poster

Re: Random color?

 
0
  #4
Feb 16th, 2007
'this is a script i used the other day, it randomizes the backcolor of the form

'code begins

Private Sub Command1_Click()
Text1.Text = Randomize("-1", "256")
Text2.Text = Randomize("-1", "256")
Text3.Text = Randomize("-1", "256")
Text4 = Text1 + Val(Text2) + Val(Text3)
Me.BackColor = Text4.Text
End Sub

Function Randomize(Lowerbound As Long, Upperbound As Long)
Randomize = Int(Rnd * Upperbound) + Lowerbound
End Function

Private Sub Form_Load()
Text1.Text = Randomize("-1", "256")
Text2.Text = Randomize("-1", "256")
Text3.Text = Randomize("-1", "256")
Text4 = Text1 + Val(Text2) + Val(Text3)
Me.BackColor = Text4.Text
End Sub

'code ends
'its a verry small code, so it shouldnt be tht hard
'right now it only cycles through the red colors, if you are able to get it to go any other colors please let me know, thnx
'if your using tht script try to keep the +val(text)'s in there
'im pretty sure it requires tht...
'it will keep comeing up with errors every 4 clicks and end your prog if you take out...

Originally Posted by KalebG View Post
ME and a freind of mine have a vB class. We are using the schools outdated microsoft visual basic 2003. We in are spare time are trying to make a "Siezure" program. The point of this program is to simply have the user click a button and the background begin to flash Random colors. We could easily use a timer with a set of colors but we want to use random colors so they are unpredictable. We have tried multiple sets of code but can't seem to get anything to work. Could anyone tell me the code for making the background color of a forum flash with random colors?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: setcho is an unknown quantity at this point 
Solved Threads: 0
setcho setcho is offline Offline
Newbie Poster

Re: Random color?

 
0
  #5
Jul 4th, 2009
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Click()
  2. Dim a As Long
  3. Dim b As Long
  4. Dim c As Long
  5. Dim d As Long
  6. a = randomise(0, 255)
  7. b = randomise(0, 255)
  8. c = randomise(0, 255)
  9.  
  10. d = a * b * c
  11.  
  12. Form1.BackColor = d
  13. End Sub
  14.  
  15. Function randomise(lowerbound As Long, upperbound As Long)
  16. randomise = Int(Rnd * upperbound) + lowerbound
  17. End Function


This is the actual code and it works
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 2
Reputation: setcho is an unknown quantity at this point 
Solved Threads: 0
setcho setcho is offline Offline
Newbie Poster

Re: Random color?

 
0
  #6
Jul 5th, 2009
And a little bit simpler

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Sub Form_Click()
  4. Form1.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
  5. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC