|
-
Feb 19th, 2005, 07:39 AM
#1
Thread Starter
Junior Member
working with time?
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
-
Feb 19th, 2005, 08:09 AM
#2
Re: working with time?
 Originally Posted by Grainne
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)
-
Feb 19th, 2005, 10:49 AM
#3
Fanatic Member
Re: working with time?
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
Do canibals not eat clowns because they taste funny? 
-
Feb 19th, 2005, 11:00 AM
#4
Re: working with time?
 Originally Posted by doofusboy
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
Thtas fine assuming the users canta djust the system clock.... Nice code by the way
-
Feb 19th, 2005, 01:48 PM
#5
Re: working with time?
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
-
Feb 19th, 2005, 05:02 PM
#6
Re: working with time?
 Originally Posted by doofusboy
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
You might want to use => in case the second doesn't hit exactly at zero.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|