Morning,
IS there any way I can use a timer so that
1. when it reaches a certain time a message box will appear
2. between say 10:00 and 4:00 I could disable certain buttons on my form
Printable View
Morning,
IS there any way I can use a timer so that
1. when it reaches a certain time a message box will appear
2. between say 10:00 and 4:00 I could disable certain buttons on my form
You may be best not working with timers there icky and it will get confusing. You could use the system clock to determine the time, (assuming the user cant change these settings)Quote:
Originally Posted by Grainne
Here's a way to use the system time to do what you want down to the second. Start a project, put a label and a command button on it. The following code will display the current time in the label, disable the command button at the hour, minute and second you specify and then re-enable the command button 5 seconds later.
In the example shown, I had this stuff occur at exactly 10:43:00 AM. Obviously you can tinker to fit your needs.
VB Code:
Option Explicit Dim showTime As Boolean Dim MyHour As Integer Dim MyMinute As Integer Dim MySecond As Integer Dim CurrHour As Integer Dim CurrMinute As Integer Dim CurrSecond As Integer Private Sub DisplayTime() Do While showTime = False Label1.Caption = Time DoEvents Check_Time Loop End Sub Private Sub Form_Load() showTime = False Me.Show DisplayTime End Sub Private Sub Form_Unload(Cancel As Integer) showTime = True End Sub Private Sub Check_Time() ' Set hour, minute and seconds for alarm MyHour = 10 MyMinute = 43 MySecond = 0 CurrHour = Hour(Time) CurrMinute = Minute(Time) CurrSecond = Second(Time) If (CurrHour = MyHour) And (CurrMinute = MyMinute) And (CurrSecond = MySecond) Then 'MsgBox "Alarm !" Command1.Caption = "Stop" Command1.Enabled = False End If If (CurrHour = MyHour) And (CurrMinute = MyMinute) And (CurrSecond = MySecond + 5) Then 'MsgBox "Alarm !" Command1.Caption = "Start" Command1.Enabled = True End If End Sub
Quote:
Originally Posted by doofusboy
Thtas fine assuming the users canta djust the system clock.... Nice code by the way ;)
or you could do a
VB Code:
Private Sub Timer1_Timer() text1.text = text1.text -1 End Sub Form_load() text1.text = 5 If text1.text <= 0 then text2.text = Split(now)(1) text1.text = 5 end sub
And then you could
If text1.text = 10:39 then 'or whatever
'blah
Quote:
Originally Posted by doofusboy
You might want to use => in case the second doesn't hit exactly at zero.