Solved

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

Posted on 2014-12-12
6
207 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 25

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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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

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!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

635 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