Question Want to type "1 month" in a text box, then for text box to count down in days and hrs

Caroline

New member
Joined
Jun 8, 2011
Messages
2
Programming Experience
5-10
Want to type "1 month" in a text box, then for text box to count down in days and hrs

I want to be able to type "1 month" into a text box, then for text box to count down in days and hrs.


For more iinformation:

I want to type in the box

"1 month" or "2 months" etc (not Years or days)

Then for another textbox to begin a countdown in days and hours from the current date and time to the one which it will be in "1" or "2 months" etc

How can I do this?
 
Last edited:
Try something like this, you would have two TextBoxes, one for the month and one for the countdown, and one start button.

Dim dMonths As Date

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    If txtMonths.Text = "" Then Exit Sub
    Dim intMonths As Integer = 0
    intMonths = CInt(txtMonths.Text.Trim)
    dMonths = New Date(Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second)
    dMonths = dMonths.AddMonths(intMonths)
    Dim tmrCountdown As New Timer
    tmrCountdown.Interval = 1000
    AddHandler tmrCountdown.Tick, AddressOf tmrCountdown_Tick
    tmrCountdown.Start()
End Sub

Private Sub tmrCountdown_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ts As TimeSpan = dMonths.Subtract(Now)
    txtCountdown.Text = ts.Days & " Days " & ts.Hours & " Hrs"
End Sub
 
dMonths = New Date(Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second)
dMonths = dMonths.AddMonths(intMonths)
equals
dMonths = Date.Now.AddMonths(intMonths)
 
Thanks :), I knew there was an easier way!
 
Back
Top