-
Heres my problem (aside from not programming too good :D)..I am making a program. 1 main form, 2 control buttons, 1 text box. I want to to work so that the user cant type in a number like 10 into the textbox then press the first command button and every 10 seconds the form color will change to something different. Then when the 2nd command button is pressed the changes stop and it goes back to the original form color..Im not really sure how to do this, any help is greatly appreciated in advance, thanx.
-
Ill create you a simple sample application. ill give you the code tommarow 8-21
-
cool
Cool thanks...I know its more than likely something very simple to do but im limited on how much learn time I can get in for vb and im still (in my opinion) not gettin any better at it :( but oh well all in its own time I guess...thanx again
-
here ya go, add 2 Command Buttons, a TextBox, and a Timer.
Code:
Dim RndColor As Integer
Private Sub Command1_Click()
Timer1.Interval = Val(Text1.Text) * 1000
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Me.BackColor = vbButtonFace
End Sub
Private Sub Timer1_Timer()
'random number 1 to 5
RndColor = Int((Rnd * 5) + 1)
With Me
Select Case RndColor
Case 1
.BackColor = vbGreen
Case 2
.BackColor = vbRed
Case 3
.BackColor = vbYellow
Case 4
.BackColor = vbBlue
Case 5
.BackColor = vbApplicationWorkspace
End Select
End With
End Sub
-
Here is the form color code:
Code:
'Timer set at 100 (faster results: set interval to 1)
'Form_Load:
Timer1.Interval = 100
Timer1.Enabled = False
Private Sub Timer1_Timer()
Me.BackColor = QBColor(Rnd * 15)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
-
Matthew:
I set the timer interval to 1, now I have a headache, be careful, that code is likely to cause siesures ;)
-
COOL
Wow! thanx! I guess im happy cause im not that good so help is HIGHLY appreciated. Mabye I can be that good someday to just be able to post code help to people on here. Thanx a million to all of you you sent me some assistance! :):):)
-
try this
I worked out this
'in a module
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
'in general
Option Explicit
Dim backclr As Long ' declare the variable publicly to hold form1.backcolor
Private Sub Cmdstart_Click()
Timer1.Enabled = True 'enabled timer
backclr = Form1.BackColor 'set the value of backcolor as soon as you hit the button
End Sub
Private Sub cmdstop_Click()
Timer1.Enabled = False ' disable timer
Form1.BackColor = backclr 'set the backcolor to the original
End Sub
Private Sub Timer1_Timer()
Dim time As Integer
time = Val(Text1.Text) & "000" 'set time = to text1.text and add the zeros to convert to seconds sience its in milliseconds
Sleep (time) 'API call sleep for the time in textbox
Form1.BackColor = QBColor(Rnd * 15) ' set the backcolor to a random value
End Sub
hope this helps
-
oh yeah and set imter interval to 1, enabled = false
-
great!
This is awesome, Im glad I got replies from different people who code it somewhat differently, it helps me to understand how to not set myself linear when thinking of how to put something "into action". Much thanks to everyone who posted. Im out
-CraZy 8
-
Hehe, Dennis, set it to black and white and you'll have to go lie down ;).
Code:
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Sub Timer1_Timer()
Me.BackColor = &H0&
Sleep 100
Me.BackColor = &HFFFFFF
Sleep 100
End Sub
You can also use RGB doing it as well for the 255 color effect ;].
Code:
Me.BackColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))
-
Yep, but it's better to use the simplest way ;)
Code:
Me.BackColor = int(rnd * &H1000000)
-
Yeah, but it would be even better if John would stop thinking about Mrs. Le Pont and fix that number problem ;)
-
Yeah, that really get's non my nerves
Code:
1000000000000000000000000000000000000000000000000000000
-
What?!?!? Let me try again
Code:
int(rnd * &H100000000000000000000000000000000000000000)
-