Results 1 to 4 of 4

Thread: Enable button using dateTime.Add(1)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    13

    Question Enable button using dateTime.Add(1)

    So yeah basically what i'm trying to do is to enable a disabled button,after 24 hours starting from the time it has been disabled!!!
    Right now my code is this:
    Code:
    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
            Static ctClicks As Integer = 0
            ctClicks += 1
            If ctClicks = 10 Then FlatButton1.Enabled = False
            Using wc As New WebClient
    
                Dim response As String = wc.DownloadString("http://website.com/text.php")
                FlatTextBox1.Text = response
    
            End Using
           
        End Sub
    I was thinking of doing something like this:
    If DateTime.Today.AddDays(1)
    Then
    FlatButton1.Enabled = True
    End If

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Enable button using dateTime.Add(1)

    Quote Originally Posted by elx00r View Post
    I was thinking of doing something like this:
    If DateTime.Today.AddDays(1)
    Then
    FlatButton1.Enabled = True
    End If
    That would not make sense. `If` statements evaluate a Boolean expression and AddDays does not return a Boolean value. What you would need to do is Start a Timer and set its Interval to the equivalent of 1 day. The Tick event will then be raised and you can enable the Button. If the application may be closed and restarted in between then you need to save the date and time somewhere external. You can then read that at startup and configure a Timer appropriately.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2015
    Posts
    13

    Re: Enable button using dateTime.Add(1)

    i was giving an idea of what i want to do...so yes the application will be closed and reopened on the same,that's why i dont know how to deal with this. How do i save that Date,time and read them on startup?! Is there any code around? Its been like 3-4 days i've been looking to solve this thing. Furthermore i dont use database!!!!! Thankyou

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Enable button using dateTime.Add(1)

    I think you've already been told how to save data externally in your other thread but you complained that that wasn't what you wanted to know. This is why they were telling you that in the first place.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width