VB 2010 Button Question.

Joined
May 15, 2012
Messages
1
Reaction score
0
Hello guys.

I've been needing a small answer to my question for a while. My question is

" How do I make it so if you click on the button once, it says a certain message and if you try clicking it again, it says something different? Then after 24 hours it resets back to the first message? "

For example. I am creating a program that gives a certain amount of GP to a game. Well I am trying to make it so if they click on a certain amount of GP, they can only click on it once every 24 hours. So the first message is "Congratulations, you now have " GP ADDED" to your account.".

If they clicked it already it says "Sorry, you have already earned your desired amount of GP today, please come back in 24 hours for some more."

Please help me A.S.A.P
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
Hello,
If you create new VB .NET project (Windows Application). Place one button on the form and copy / paste below code into Form1.vb file (replace all text).
This example performs exactly what you wanted.

PublicClass Form1
Dim lastAddedDate As DateTime

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
lastAddedDate = readDateFromDatabase()
EndSub

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim span As TimeSpan = Now().Subtract(lastAddedDate)

If span.TotalHours > 23 Then
lastAddedDate = Now()
saveDateToDatabase(lastAddedDate)
MsgBox("Done, my Master!")
Else
MsgBox("Sorry. You can't do it yet! Wait another " & Math.Ceiling(24 - span.TotalHours) & " hours, please.")
EndIf
EndSub

PrivateFunction readDateFromDatabase() As DateTime
'add here the code to read data from db, below is just for example
Return Now().AddDays(-2)
EndFunction

PrivateSub saveDateToDatabase(ByVal dateToSave As DateTime)
'add here the code to save date

EndSub
EndClass
 
Joined
Jun 12, 2012
Messages
53
Reaction score
0
Yes! That's little strange. I answered as JohnS at first, but they banned me for spam (!) and that answer dissapeared. Admin didn't reply for my email about strange ban strategy, so I decided to create another account and post reply again. When it was done, previous answer magically appeared again. Strange... Anyway, I'm goddfellow now - until next ban ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top