Question countdown timer problem!

aksl

Member
Joined
Jan 31, 2014
Messages
11
Programming Experience
Beginner
I wrote a code for a countdown timer. It works fine. When i select a date from datetimepicker1,it starts counting.But after closing & re starting my software, datetimepicker1 comes back to date of today(IT MEANS: It doesn't keep the date i choosed first). it causes to count to wrong date.

i want to lock the datetimepicker1 after choosing a date. How to get kept the date i choosed in datetimepicker1 when opening it another times?

this is the code i wrote,

Dim startdate As DateTime = DateTime.Parse(Date.Now)
        Dim enddate As DateTime = DateTime.Parse(DateTimePicker1.Text)
        Dim ts As TimeSpan = enddate.Subtract(startdate)
        Label1.Text = CStr(ts.Days) & " Days Remaining "
        
If ts.Days = 0 Then
            Timer1.Dispose()
            Label2.Text = "Today is your Birthday !"
        End If


i want to lock the datetimepicker1 after choosing a date. How to get kept the date i choosed in datetimepicker1 when opening it another times?

how to correct this my brothers. Please hep me.
 
Last edited by a moderator:
You need to save the selected date to an external file or the like so that you can then read it again the next time the application runs. The simplest option is to use My.Settings and bind the setting to the control property. That way, the saving and loading of the value will be done automatically.

There are two ways to do this. You can create the setting first and then bind the control property to it or you can create and bind at the same time. Normally I would recommend the latter when you know you're going to bind but I'll suggest the former in this case so you can familiarise yourself with both processes.

First, open the Settings page of the project properties. Create a new setting with an appropriate name, User scope and a type of DateTime. You'll have to give the setting a default vale. Now, if you want to, you can access that setting in code using My.Settings.SomeSetting, where SomeSetting is the name that you gave the setting that you created.

Next, select your DateTimePicker in the designer and open the Properties window. Expand the (ApplicationSettings) node, select the (PropertyBinding) node and click the browse (...) button. Select the property you want to bind (Value in this case) and click the drop-down arrow. Now you can create a new setting to bind to or bind to an existing setting.

Once the binding is done, the control property will be kept in sync with the setting and the setting will be saved to the config file at shutdown and loaded at startup.
 
Back
Top