Hi I have 2 Date properties on a form.
mdtValidTo & mdtOrigValidTo
Question is why are they both set to 9/30/19 after the code runs?
This must be caused by them being a property of the form and not being Dimed as New Date.
How do I get around this.
mdtOrigValidTo = mdtValidTo <<<<<<<<<<<<<<<<<<< They are both set to 9/30/18
if mnMultiYear = 2 then
mdtValidTo.year = mdtValidTo.Year + 1 <<<<<<<<<<<<<<<<<<< mdtValidTo is set to 9/30/19
Elseif mnMultiYear = 3 then
mdtValidTo.year = mdtValidTo.Year + 2
End
<<<<<<<<<<<<<<<<<<< They are both set to 9/30/19
Well if it was being set to todays date Id have said they were initialized when created by the form. But the fact that it is a date in the future has me stumped.
I can’t find the information but I think that when you do
mdtOrigValidTo = mdtValidTo
on a Date objet, you are telling mdtOrigValidTo that will be the same as mdtValidTo and not what you think as “only copy the date from mdtValidTo to mdtOrigValidTo”.
So every time mdtValidTo changes, then mdtOrigValidTo will change.
[quote=406462:@Richard Albrecht]Hi I have 2 Date properties on a form.
mdtValidTo & mdtOrigValidTo
Question is why are they both set to 9/30/19 after the code runs?
This must be caused by them being a property of the form and not being Dimed as New Date.
How do I get around this.
[code]
mdtOrigValidTo = mdtValidTo <<<<<<<<<<<<<<<<<<< They are both set to 9/30/18
if mnMultiYear = 2 then
mdtValidTo.year = mdtValidTo.Year + 1 <<<<<<<<<<<<<<<<<<< mdtValidTo is set to 9/30/19
Elseif mnMultiYear = 3 then
mdtValidTo.year = mdtValidTo.Year + 2
End
<<<<<<<<<<<<<<<<<<< They are both set to 9/30/19
[/code][/quote]
Because mdtOrigValidTo and mdtValidTo are both objects of type Date. When you write:
mdtOrigValidTo = mdtValidTo
both of those variables point to the same place in memory and changing one therefore changes both.
Well, like Paul said dates are a class and you have to treat them as such. Use new to create the instance of the class. If you put it on the window as a property it’s a NIL object until you initialize it somehow.
If mdtOrigValidTo is not nil (say, read from a database) then you could do something like this:
mdtValidTo = new Date(mdtOrigValidTo) //Automatically initializes the date object with the one passed in but yet are separate instances
or alternatively you could do this:
mdtValidTo = new date //Create the instance
mdtValidTo.TotalSeconds = mdtOrigValidTo.TotalSeconds //Set value to that of original