Solved

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

Posted on 2014-12-12
6
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

751 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