VB 2010 Button Question.

Discussion in 'Webmaster / Programming' started by larry9000, May 15, 2012.

  1. larry9000

    larry9000

    Joined:
    May 15, 2012
    Messages:
    1
    Likes Received:
    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
     
    larry9000, May 15, 2012
    #1
    1. Advertisements

  2. larry9000

    goodfellow

    Joined:
    Jun 12, 2012
    Messages:
    53
    Likes Received:
    0
    Location:
    Earth
    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
     
    goodfellow, Jun 12, 2012
    #2
    1. Advertisements

  3. larry9000

    goodfellow

    Joined:
    Jun 12, 2012
    Messages:
    53
    Likes Received:
    0
    Location:
    Earth
    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 ;)
     
    goodfellow, Jun 13, 2012
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zcast
    Replies:
    0
    Views:
    869
    Zcast
    Jun 17, 2011
  2. rbotelho
    Replies:
    0
    Views:
    1,819
    rbotelho
    Jul 27, 2011
  3. Tagy

    Visual Studio 2010 and VoIP SIP SDK

    Tagy, Feb 24, 2012, in forum: Webmaster / Programming
    Replies:
    0
    Views:
    1,419
  4. mward

    Headers and Sub-headers in Access 2010

    mward, Mar 15, 2012, in forum: Webmaster / Programming
    Replies:
    0
    Views:
    891
    mward
    Mar 15, 2012
  5. joeyc0323

    Help with browse button in Access 2010

    joeyc0323, Apr 13, 2012, in forum: Webmaster / Programming
    Replies:
    0
    Views:
    1,259
    joeyc0323
    Apr 13, 2012
Loading...

Share This Page