Solved

how to rollback to previously selected date upon denial form a msgbox

Posted on 2014-12-12
6
204 Views
Last Modified: 2014-12-14
i have a dateimtepicker, and if i select a certain date, according to certain conditions, a msgbox appears, with a yes/no buttons, if i select yes, date will advance, and thats fine, but if i select (no) the wrong day i selected stays or gets selected, i need for this datepicker to go back to the previous value it was before i pressed no, so once i press no then the date goes back to the value it was set on before. like an undo thing sort of...

thanks
0
Comment
Question by:ahashash
6 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 40497597
Do you mind posting that area of your code?
0
 

Author Comment

by:ahashash
ID: 40497632
Private Sub picBox_VisibleChanged(sender As System.Object, e As System.EventArgs) Handles FSYELLOW.VisibleChanged
        If picBox.Visible = True Then
            If MessageBox.Show("F.S, DATE NEAR, SO, A MONTH EXTENSION? ", "ALMOST DUE" & vbNewLine, MessageBoxButtons.YesNo) = DialogResult.Yes Then
                FSDATEDateTimePicker.Value = FSDATEDateTimePicker.Value.AddDays(31.0)
                SAVEDETAILZ.PerformClick()
            Else
                   -----------??------------->>UNDO CHANGES <<------------??-----------
                Exit Sub
            End If
        End If
    End Sub

actually the picture box will automatically appear once a certain date reaches
thanx
0
 
LVL 11

Accepted Solution

by:
LordWabbit earned 500 total points
ID: 40497675
You will need to store it locally, in memory, so every time you change your datetime picker you would keep that in a local variable so that if needed you can revert back to it.

Dim currentDate As DateTime
Private Sub picBox_VisibleChanged(sender As System.Object, e As System.EventArgs) Handles FSYELLOW.VisibleChanged
        If picBox.Visible = True Then
            If MessageBox.Show("F.S, DATE NEAR, SO, A MONTH EXTENSION? ", "ALMOST DUE" & vbNewLine, MessageBoxButtons.YesNo) = DialogResult.Yes Then
                FSDATEDateTimePicker.Value = FSDATEDateTimePicker.Value.AddDays(31.0)
                currentDate = FSDATEDateTimePicker.Value  ' update the currentDate
                SAVEDETAILZ.PerformClick()
            Else
                   FSDATEDateTimePicker.Value = currentDate ' resort to the previous date
                Exit Sub
            End If
        End If
    End Sub
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Expert Comment

by:LordWabbit
ID: 40497677
Also there are not always 31 days in a month, there are actually less months with 31 days than any of the other's.  Not sure of your exact usage scenario but if you are always working from the first of the month and trying to get to the next, then a simple .Value.AddMonth(1) would work.  If however you are on the 5th day of a month and trying to get the first day of the next month things get a bit more involved.  Working with dates is always a pain, always try to use the built in date calculators, don't invent your own, someone else has already done it and tested it to death and taken into account things like leap years etc.  Build on their code and save yourself a lot of time and effort.
0
 
LVL 40
ID: 40498239
I would not declare the currentDate variable outside of the event method.

Doing so, you are creating a member for the form. This variable is visible everywhere in the form (which would make bugs harder to pinpoint) and takes up memory as long as the form is on the screen, no matter if you use it or not.

Because you need it only inside of the method you are better declaring the variable at the beginning of the method. That way, it cannot modified outside of the method, and it exists in memory only for the time that the method is executing. It is automatically destroyed when you exit the sub.
0
 
LVL 11

Expert Comment

by:LordWabbit
ID: 40498645
I agree with all of your points save one.  Considering the event that is being used how would you know what the date was BEFORE the event was raised so that you could revert back to it?  Also the date in question is a value type and not a reference type and does not take up much space on the stack, and hence nothing on the heap. You could read the data from the original source, which is probably a database, create a connection, command, adapter, table, unboxing to datetime. Which would probably involve disk and network IO which we all know is a lot more expensive than storing 64 bits in memory.  Considering that, which option would be more efficient?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Work with App store 7 52
VB.Net Report Printing Issue 3 35
Need to start a web service from Visual Studio 2015 Pro 2 24
location of a form 2 14
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question