VB 2010 Button Question.

Discussion in 'Coding' started by larry9000, May 15, 2012.

  1. larry9000

    larry9000

    Joined:
    May 15, 2012
    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
    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
    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:
    1,047
    Zcast
    Jun 17, 2011
  2. rbotelho
    Replies:
    0
    Views:
    2,150
    rbotelho
    Jul 27, 2011
  3. Tagy
    Replies:
    0
    Views:
    1,760
  4. mward
    Replies:
    0
    Views:
    1,053
    mward
    Mar 15, 2012
  5. joeyc0323
    Replies:
    0
    Views:
    1,526
    joeyc0323
    Apr 13, 2012
  6. rpes
    Replies:
    2
    Views:
    1,997
    bootneck02
    Apr 15, 2012
  7. klund5
    Replies:
    5
    Views:
    1,367
  8. newuser123
    Replies:
    2
    Views:
    1,277
    newuser123
    Aug 30, 2012
Loading...