Click to See Complete Forum and Search --> : How to lock a button until next day?
buller
Mar 5th, 2010, 03:40 AM
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.
jmcilhinney
Mar 5th, 2010, 07:26 AM
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.
Negative0
Mar 5th, 2010, 08:18 AM
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.
jmcilhinney
Mar 5th, 2010, 08:22 AM
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.
si_the_geek
Mar 5th, 2010, 08:42 AM
Thread moved to 'Mobile Development' forum
(thanks for letting us know jmcilhinney :thumb: )
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.