PC Review


Reply
Thread Tools Rate Thread

VB 2010 Button Question.

 
 
New Member
Join Date: May 2012
Posts: 1
 
      15th May 2012
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
 
Reply With Quote
 
 
 
 
Member
goodfellow's Avatar
Join Date: Jun 2012
Location: Earth
Posts: 53
 
      12th Jun 2012
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
 
Reply With Quote
 
 
 
 
Member
goodfellow's Avatar
Join Date: Jun 2012
Location: Earth
Posts: 53
 
      13th Jun 2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Access 2010 Forms - Converting 2007 Client into 2010 Web Tom van Stiphout Microsoft Access Form Coding 0 26th Mar 2010 03:03 PM
RE: Access 2010 Forms - Converting 2007 Client into 2010 Web Maurice Microsoft Access Form Coding 0 26th Mar 2010 02:48 PM
Form 4 Range of time from 1/20/2010 4:00 AM To 1/21/2010 10:00 AM Peter Gonzalez Microsoft Excel Worksheet Functions 2 26th Jan 2010 07:58 PM
Can't open workbook in excel 64 bit 2010 - but can in excel 2010 3 Darrell Microsoft Excel Programming 5 12th Jan 2010 10:03 PM
Office 2010 & Outlook 2010 and Business Contact Manager AvrahamC Microsoft Outlook BCM 0 4th Jan 2010 02:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:29 AM.