Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-12-12
6
Medium Priority
?
209 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 2000 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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