Results 1 to 17 of 17

Thread: How do i enable/disable a button during a specific time of the day? PLS HELP

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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..

  2. #2
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    vb Code:
    1. If TimeOfDay = "28:20:20" Then
    2. Button1.Enabled = False
    3. 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.

  3. #3
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    What's your code ?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    Quote Originally Posted by whythetorment View Post
    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

  5. #5
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Question Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    Quote Originally Posted by jbaptist View Post
    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:
    1. Public Class Form1
    2.  
    3.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    4.         If TimeOfDay = "12:09:30" Then
    5.             Button1.Enabled = False
    6.             Timer2.Enabled = True
    7.             Timer1.Stop()
    8.         End If
    9.     End Sub
    10.  
    11.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    12.         If TimeOfDay = "13:09:30" Then
    13.             Button1.Enabled = True
    14.             Timer1.Enabled = True
    15.             Timer2.Stop()
    16.         End If
    17.     End Sub
    18. 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.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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

  7. #7
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    What if the user changes the time =)
    Have you tried Google?

  8. #8
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    Quote Originally Posted by jbaptist View Post
    '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?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    my mistake...

  11. #11
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: How do i enable/disable a button during a specific time of the day? PLS HELP

    Quote Originally Posted by jbaptist View Post
    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.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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?

  13. #13
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    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.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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...

  15. #15
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    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...

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    20

    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..

  17. #17
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    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
  •  



Click Here to Expand Forum to Full Width