Hello, manishshrestha60.
This is really easy to do. Basically what you need to do is mark the date the button is pressed, increment it for seven days and then set button's enabled property to false.
1. Go to your project's settings (Project -> <name> Properties...) and create these settings:
Code:
NAME TYPE SCOPE VALUE
day String User 0
month String User 00
year String User 0000
disabled Boolean User False
2. Declare three string variables which will be used as a current date.
[code2=vbnet]Private day, month, year As String[/code2]
3. Double-click on the form to generate Form.Load event. Rewrite or copy'n'paste this code snippet:
[code2=vbnet]' Sets the date variables to computer's current date.
day = My.Computer.Clock.LocalTime.Day
month = My.Computer.Clock.LocalTime.Month
year = My.Computer.Clock.LocalTime.Year
' Checks whether the button is enabled or disabled.
' If the button is disabled, it makes sure it is disabled
' for seven days.
If My.Settings.disabled = False Then
My.Settings.day = day
My.Settings.month = month
My.Settings.year = year
Button1.Enabled = True
Else
Button1.Enabled = False
If year = My.Settings.year Then
If month = My.Settings.month Then
If day = (My.Settings.day + 7) Or day > (My.Settings.day + 7) Then
My.Settings.disabled = False
Button1.Enabled = True
End If
Else
My.Settings.disabled = False
Button1.Enabled = True
End If
Else
My.Settings.disabled = False
Button1.Enabled = True
End If
End If
My.Settings.Save() ' <-- Don't delete this line. It's important.[/code2]
4. Double-click on the button. Rewrite or copy'n'paste this code snippet:
[code2=vbnet]My.Settings.disabled = True
Button1.Enabled = False[/code2]
I assure you this works because I tested it by changing my computer's date.
If you're stuck at some point in this
tutorial, click
here to see the full code.
I hope this helped you.
NOTE: I was writing this when there was no replies and when I needed the link to the thread, I noticed that Brandon has already replied. Since I took my time write this, I decided to post it anyway.