Solved

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

Posted on 2014-12-12
6
198 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 23

Expert Comment

by:NVIT
Comment Utility
Do you mind posting that area of your code?
0
 

Author Comment

by:ahashash
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:LordWabbit
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now