New topic: Is this a Bug? 2 Date Vars change when one gets updated.
<http://forums.realsoftware.com/viewtopic.php?t=46656> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message Hawkcode Post subject: Is this a Bug? 2 Date Vars change when one gets updated.Posted: Wed Jan 23, 2013 4:26 pm Joined: Sat Jul 24, 2010 12:20 am Posts: 39 Hi, This is strange. Basically I have 2 Date Vars and when I set one they both change??? Dim ldDate as Date Dim ld3MoDate as Date Dim ldFinalDate as Date ldDate = StrToDate( txtCurrentRunMonth.Text) if lsKind = "NormalRun" Then ld3MoDate = ldDate ldFinalDate = ldDate ld3MoDate.Month = ld3MoDate.Month + 3 '<<<<<<When this updates ls3MoDate, ldFinalDate gets updated too!!! ld3MoDate.Day = 1 ld3MoDate.Day = ld3MoDate.day - 1 ldFinalDate.Month = ldFinalDate.Month + 1 ldFinalDate.Day = 1 ldFinalDate.Day = ldFinalDate.day - 1 lsWhere = "( tblMembership.ValidTo = '" + ldFinalDate.SQLDate + "' OR tblMembership.ValidTo = '" + ld3MoDate.SQLDate + "' )" end Why is this happening? Can someone please explain this to me? Thanks Rich Top markwalsh Post subject: Re: Is this a Bug? 2 Date Vars change when one gets updated.Posted: Wed Jan 23, 2013 4:43 pm Joined: Wed May 20, 2009 4:43 pm Posts: 932 Hawkcode wrote:Hi, This is strange. Basically I have 2 Date Vars and when I set one they both change??? Dim ldDate as Date Dim ld3MoDate as Date Dim ldFinalDate as Date ldDate = StrToDate( txtCurrentRunMonth.Text) if lsKind = "NormalRun" Then ld3MoDate = ldDate ldFinalDate = ldDate ld3MoDate.Month = ld3MoDate.Month + 3 '<<<<<<When this updates ls3MoDate, ldFinalDate gets updated too!!! ld3MoDate.Day = 1 ld3MoDate.Day = ld3MoDate.day - 1 ldFinalDate.Month = ldFinalDate.Month + 1 ldFinalDate.Day = 1 ldFinalDate.Day = ldFinalDate.day - 1 lsWhere = "( tblMembership.ValidTo = '" + ldFinalDate.SQLDate + "' OR tblMembership.ValidTo = '" + ld3MoDate.SQLDate + "' )" end Why is this happening? Can someone please explain this to me? Thanks Rich Your problem is here: ld3MoDate = ldDate ldFinalDate = ldDate You just set both references to the same date object. Instead, try this: ld3MoDate = StrToDate( txtCurrentRunMonth.Text) ldFinalDate = StrToDate( txtCurrentRunMonth.Text) _________________ RB 2009r4 Windows XP Top jakuno Post subject: Re: Is this a Bug? 2 Date Vars change when one gets updated.Posted: Wed Jan 23, 2013 4:45 pm Joined: Fri Aug 31, 2012 3:56 pm Posts: 73 http://forums.realsoftware.com/viewtopic.php?f=10&t=46165&hilit=date Top ktekinay Post subject: Re: Is this a Bug? 2 Date Vars change when one gets updated.Posted: Wed Jan 23, 2013 5:11 pm Joined: Mon Feb 05, 2007 5:21 pm Posts: 380 Location: New York, NY Or: ld3MoDate = new Date( ldDate ) ldFinalDate = new Date( ldDate ) This will clone the Dates instead of simply assigning them. _________________ Kem Tekinay MacTechnologies Consulting http://www.mactechnologies.com/ Need to develop, test, and refine regular expressions? Try RegExRX. Top Hawkcode Post subject: Re: Is this a Bug? 2 Date Vars change when one gets updated.Posted: Wed Jan 23, 2013 7:15 pm Joined: Sat Jul 24, 2010 12:20 am Posts: 39 Thanks, I actually came up with: ld3MoDate = StrToDate( txtCurrentRunMonth.Text) ldFinalDate = StrToDate( txtCurrentRunMonth.Text) Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml rbforumnotifier@monkeybreadsoftware.de