| | |
Random color?
![]() |
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.
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 1
•
•
•
•
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
'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...
'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...
•
•
•
•
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?
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_Click() Dim a As Long Dim b As Long Dim c As Long Dim d As Long a = randomise(0, 255) b = randomise(0, 255) c = randomise(0, 255) d = a * b * c Form1.BackColor = d End Sub Function randomise(lowerbound As Long, upperbound As Long) randomise = Int(Rnd * upperbound) + lowerbound End Function
This is the actual code and it works
•
•
Join Date: Jun 2009
Posts: 2
Reputation:
Solved Threads: 0
And a little bit simpler 

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private Sub Form_Click() Form1.BackColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) End Sub
![]() |
Similar Threads
- Projects for the Beginner (Python)
- Java applets (Java)
- Please Please Help. Computer Crashing... seemingly random intervals. (Windows NT / 2000 / XP)
- trouble with long output string, plz help (PHP)
- how to manipulate characters in strings (PHP)
- Help with algorithm design (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: im looking for a Point of Sale System that made in Vb?.
- Next Thread: Please help me
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






