Results 1 to 8 of 8

Thread: How to lock a button until next day?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    1

    How to lock a button until next day?

    I'm trying to make this simple program in visual studio 2008.

    It's for a pocket pc

    It's with a randomizer, where you press a button, and it'll pick a random sentence.

    Then made a variable with 10 random sentences, that's all good and working BUT i would like you to be able to only press the button once a day, and then lock it, and then it will ofcourse get unlocked the next day.

    For example you press button at 4 pm, then it'll get locked until 12 @ midnight, then unlocks, and process restarts.

    So you will have sentence a day, and no more.

    If you have any idea about this, i would appreciate some help, havent been able to find anything about it unfortunately.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to lock a button until next day?

    If this is for a mobile app the it really should be posted in the Mobile forum because the considerations are different. I've asked the mods to move it.

    You should handle the Click event of the Button and set its Enabled property to False. You can then calculate the amount of time until midnight and use that to set the Interval of a Timer, which you then Start. When the Timer Ticks, you enable the Button. This will work in a PC app and I assume a mobile app too, but I'm not 100% sure.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: How to lock a button until next day?

    Quote Originally Posted by jmcilhinney View Post
    You should handle the Click event of the Button and set its Enabled property to False. You can then calculate the amount of time until midnight and use that to set the Interval of a Timer, which you then Start. When the Timer Ticks, you enable the Button. This will work in a PC app and I assume a mobile app too, but I'm not 100% sure.
    I don't know if this is a good option, because once the user quits the app and comes back in the button would be re-enabled. I think the OP might be better off persisting that information in a file or registry and using a timer to read the value every few seconds/minutes depending on the desired functionality.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to lock a button until next day?

    Quote Originally Posted by Negative0 View Post
    I don't know if this is a good option, because once the user quits the app and comes back in the button would be re-enabled. I think the OP might be better off persisting that information in a file or registry and using a timer to read the value every few seconds/minutes depending on the desired functionality.
    I did mean to cover that contingency but got distracted and forgot to finish before submitting. You would save a Date somewhere and, when the app started up, you'd compare that Date to the current date. If they were the same day then you'd do the same again, i.e. disable the Button and set the Timer to Tick at midnight.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to lock a button until next day?

    Thread moved to 'Mobile Development' forum

    (thanks for letting us know jmcilhinney )

  6. #6
    New Member
    Join Date
    Feb 2015
    Posts
    13

    Re: How to lock a button until next day?

    Hi there mate, i am on the same problem as yours! Would you mind please explaining me how did you come through? thank you very much!!!!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to lock a button until next day?

    Quote Originally Posted by elx00r View Post
    Hi there mate, i am on the same problem as yours! Would you mind please explaining me how did you come through? thank you very much!!!!
    This thread is five years old. Maybe you should start a new one for yourself, particularly given that the person who asked the question here has not posted again since then.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    New Member
    Join Date
    Feb 2015
    Posts
    13

    Re: How to lock a button until next day?

    yeah i learnt that later
    i even made one of my own...but nobody seems to explain it to me good enough so that i could understand. I thought the guy who made this post coul've helped me...

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