-
Oct 29th, 2009, 05:04 AM
#1
Thread Starter
Junior Member
How do i enable/disable a button during a specific time of the day? PLS HELP
I have 2 buttons on the form, Button A and button B.
I want to enable button A from 6am till 6pm from Monday to Friday and to disable button B during 6am until 6pm.
And I want to disable button A from 6.01pm till 11.59pm.
During saturday, only button B is enabled for the whole day.
CAN YOU PLS HELP BECAUSE I CANT GET THE CODING RIGHT.
THANK YOU IN ADVANCE..
-
Oct 29th, 2009, 05:06 AM
#2
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
vb Code:
If TimeOfDay = "28:20:20" Then
Button1.Enabled = False
End If
Note: You can use timer for this.
Then put timer stop and start another timer which enables it at specific time.
(EDIT: I tried this and it works.)
Last edited by Zeuz; Oct 29th, 2009 at 05:09 AM.
-
Oct 29th, 2009, 05:06 AM
#3
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
-
Oct 29th, 2009, 05:12 AM
#4
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
 Originally Posted by whythetorment
What's your code ?
'If (intHour > 5 And intHour < 18) And (intDay > 0 And intDay < 5) Then
'btnRate2.Enabled = False
'btnRate1.Enabled = True
'Else
'btnRate2.Enabled = True
'btnRate1.Enabled = False
'End If
================================
If inthour > 5 And inthour < 18 And intDay > 0 And intDay < 5 Then
btnRate2.Enabled = False
'Else
'btnRate2.Enabled = True
End If
End Sub
-
Oct 29th, 2009, 05:13 AM
#5
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
 Originally Posted by jbaptist
I have 2 buttons on the form, Button A and button B.
I want to enable button A from 6am till 6pm from Monday to Friday and to disable button B during 6am until 6pm.
And I want to disable button A from 6.01pm till 11.59pm.
During saturday, only button B is enabled for the whole day.
CAN YOU PLS HELP BECAUSE I CANT GET THE CODING RIGHT.
THANK YOU IN ADVANCE..
Code Code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If TimeOfDay = "12:09:30" Then
Button1.Enabled = False
Timer2.Enabled = True
Timer1.Stop()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If TimeOfDay = "13:09:30" Then
Button1.Enabled = True
Timer1.Enabled = True
Timer2.Stop()
End If
End Sub
End Class
Here is one full example for enabling and disabling it at current time, but remember use same system from Date Time if you want specific date.
-
Oct 29th, 2009, 05:15 AM
#6
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
'If (intHour > 5 And intHour < 18) And (intDay > 0 And intDay < 5) Then
'btnRate2.Enabled = False
'btnRate1.Enabled = True
'Else
'btnRate2.Enabled = True
'btnRate1.Enabled = False
'End If
================================
If inthour > 5 And inthour < 18 And intDay > 0 And intDay < 5 Then
btnRate2.Enabled = False
'Else
'btnRate2.Enabled = True
End If
End Sub
jbaptist is online now Rate this post
Add to jbaptist's Reputation Report Post Edit/Delete Message
-
Oct 29th, 2009, 05:16 AM
#7
Addicted Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
What if the user changes the time =)
-
Oct 29th, 2009, 05:18 AM
#8
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
 Originally Posted by jbaptist
'If (intHour > 5 And intHour < 18) And (intDay > 0 And intDay < 5) Then
'btnRate2.Enabled = False
'btnRate1.Enabled = True
'Else
'btnRate2.Enabled = True
'btnRate1.Enabled = False
'End If
================================
If inthour > 5 And inthour < 18 And intDay > 0 And intDay < 5 Then
btnRate2.Enabled = False
'Else
'btnRate2.Enabled = True
End If
End Sub
jbaptist is online now Rate this post
Add to jbaptist's Reputation Report Post Edit/Delete Message
Mine code work: 
Why you posted your code two times?
Maybe you edit it?
-
Oct 29th, 2009, 05:19 AM
#9
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
they cant change the time coz im using a program called winlock..
the only problem is that if the user exits from the program and starts the program at a later time, will the button1 still be disabled?
-
Oct 29th, 2009, 05:20 AM
#10
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
-
Oct 29th, 2009, 05:21 AM
#11
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
 Originally Posted by jbaptist
they cant change the time coz im using a program called winlock..
the only problem is that if the user exits from the program and starts the program at a later time, will the button1 still be disabled?
True, but you didn't told anything about program shutting down.
-
Oct 29th, 2009, 05:25 AM
#12
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
lets say, i want to disable button1 and Enable button2 from 6pm onwards, what if the user exits and starts the program at 7pm? Will button1 still be disabled?
-
Oct 29th, 2009, 05:26 AM
#13
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
My code won't do that.
But if we spoke only about disabling and enabling it works.
-
Oct 29th, 2009, 05:33 AM
#14
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
pls help me coz this is really frustrating trying to get it right..
DESCRIPTION OF PROGRAM FUNCTION:
button1 is enabled from 6am - 6pm Monday to Friday
button2 is enabled from 6pm till 11pm
button1 is disabled on Saturday and Sunday...
-
Oct 29th, 2009, 06:01 AM
#15
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
Try something like this... Haven't tested it so you might need to play around with it.
Code:
Dim dt As DateTime
dt = Now
If (dt.DayOfWeek = DayOfWeek.Saturday Or dt.DayOfWeek = DayOfWeek.Sunday) Then
button1.enabled = False
Else
If (TimeOfDay >= "06:00:00" And TimeOfDay <= "18:00:00") And (dt.DayOfWeek >= DayOfWeek.Monday And dt.DayOfWeek <= DayOfWeek.Friday) Then
button1.enabled = True
Else
button1.enabled = False
End If
End If
If (TimeOfDay >= "18:00:00" And TimeOfDay <= "23:00:00") Then
button2.enabled = True
End If
Last edited by whythetorment; Oct 29th, 2009 at 06:05 AM.
Reason: Sorry... editing it a few times...
-
Oct 29th, 2009, 06:34 AM
#16
Thread Starter
Junior Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
Dear Whythetorment,
IT WORKS LIKE A CHARM..... Excellent!!!
You've made my day... if only i could buy u a good lunch... thanks again..
-
Oct 29th, 2009, 06:58 AM
#17
Hyperactive Member
Re: How do i enable/disable a button during a specific time of the day? PLS HELP
Glad it works
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
|