Lol, too true. However, I'm sure I won't be doing the same job by the time this code fails to work for a leap year. :) Thanks for everyones imput. -----Original Message----- From: jawsscripts-bounce@xxxxxxxxxxxxx [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Martin Slack Sent: Saturday, February 20, 2010 5:15 PM To: jawsscripts@xxxxxxxxxxxxx Subject: [jawsscripts] Re: inserting yesterday's date with a script Oops, thanks Travis. Luckily we have nearly 90 years left to apply the final polish to the code. Martin ----- Original Message ----- From: "Travis Roth" <travis@xxxxxxxxxxxxxx> To: <jawsscripts@xxxxxxxxxxxxx> Sent: Saturday, February 20, 2010 9:03 PM Subject: [jawsscripts] Re: inserting yesterday's date with a script > Hi Martin, > > The leap year test is not quite complete. Centuries that are then > divisible > by 4 are leap years, not just any century is not a leap year. So 2000 was > a > leap year, 2100 is not, as 21 is not divisible by 4. > > > -----Original Message----- > From: jawsscripts-bounce@xxxxxxxxxxxxx > [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Martin Slack > Sent: Saturday, February 20, 2010 2:16 PM > To: jawsscripts@xxxxxxxxxxxxx > Subject: [jawsscripts] Re: inserting yesterday's date with a script > > Jason, > > The test for a leap year is not quite complete, in that years divisible > by > > both 4 and 100 are not leap years. One way to test would be to eliminate > the century years first by checking with StringRight(SysGetDate("yyyy"), > 2): > > if (StringRight(SysGetDate("yyyy"), 2) == "00") then > ; not a leap year > else > if (StringToInt(SysGetDate("yyyy") % 4) == 0) then > ; a leap year > > Martin > > > ----- Original Message ----- > From: "Jason Boston" <jwb3301@xxxxxxx> > To: <jawsscripts@xxxxxxxxxxxxx> > Sent: Saturday, February 20, 2010 5:49 PM > Subject: [jawsscripts] Re: inserting yesterday's date with a script > > >> Paul, >> First, Let me say, I'm extremely grateful for your assistance. This will >> save me that much more time at work. >> That is excellent code. I was able to drop it right into my script with >> very >> little change. When I asked the original question, I had something like >> your >> solution in mind, I was just at a loss as to how I would separate the >> pieces of the date string into a int instead of a string. I also didn't >> know >> how to use the constant declaration the way you did. I was also hoping >> someone like yourself would give me what I needed to paste in the prior >> date >> so I could build on it to be able to paste the previous date for the last >> 4 >> days. It took a little working, but I greatly expanded your idea and made >> it work. I wrote the code in my notepad script for easy testing. I'll >> port >> it over to MS Access later. For each successive prior date, I wrote a >> function. I assigned each one to control+shift+1, control+shift+2, etc. >> >> If anyone can find a flaw based on some date I didn't think to try, >> please >> do so. I would love to fix it now rather then later. :) I tested it on >> leap >> years from march 1 through march 8 and I also tested jan 1 and 2. Of >> course >> I tested the current date too, but that was easy since it didn't affect >> the >> prior month. >> >> Control+shift+1 uses the function and script you sent me. >> Control+shift+2 pastes in the date for 2 days ago. >> Control+shift+3 paste in the date for 3 days ago >> Control+shift+4 pastes in the date for 4 days ago. >> >> I've included the code below so you can see what I did. >> >> *** start copy *** >> >> CONST >> PreviousMonthLastDay = "31|31|28|31|30|31|30|31|31|30|31|30" >> >> CONST >> PreviousMonthLast2Day = "30|30|27|30|29|30|29|30|30|29|30|29" >> >> CONST >> PreviousMonthLast3Day = "29|29|26|29|28|29|28|29|29|28|29|28" >> >> CONST >> PreviousMonthLast4Day = "28|28|25|28|27|28|27|28|28|27|28|27" >> >> String Function PreviousDaysDate () >> >> var >> >> INT Day, >> INT Month, >> INT year >> >> LET Day = StringToInt (SysGetDate ("dd")) >> LET Month = StringToInt (SysGetDate ("MM")) >> LET Year = StringToInt (SysGetDate ("yyyy")) >> >> IF (Day > 1) THEN ; not first day of month >> >> LET Day = Day - 1 >> >> ELSE ;day=1, so last day of previous month needed, then previous month >> also >> needed >> >> LET Day = StringToInt (StringSegment (PreviousMonthLastDay, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 29 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was first day of month, or not >> >> ; all integers now set to the previous day >> >> RETURN (SysGetDate ("MM/dd/yyyy", Month, Day, Year)) >> >> EndFunction >> >> >> Script WritePreviousDaysDate () >> >> TypeString (PreviousDaysDate ()) >> EnterKey () >> >> EndScript >> >> >> String Function Previous2DaysDate () >> >> var >> INT Day, >> INT Month, >> INT year >> >> LET Day = StringToInt (SysGetDate ("dd")) >> LET Month = StringToInt (SysGetDate ("MM")) >> LET Year = StringToInt (SysGetDate ("yyyy")) >> >> IF (Day > 2) THEN >> ; if today is > then the 2nd do this to adjust back 2 days >> LET Day = Day - 2 >> Else >> >> ; tests to see if today is the 2nd of the month. >> IF (Day == 2) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLastDay, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 29 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 2nd day of month >> >> IF (Day == 1) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast2Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 28 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 1st day of month >> >> EndIf >> >> ; all integers now set to the previous day >> >> RETURN (SysGetDate ("MM/dd/yyyy", Month, Day, Year)) >> >> EndFunction >> >> >> Script WritePrevious2DaysDate () >> >> TypeString (Previous2DaysDate ()) >> >> EnterKey () >> >> EndScript >> >> String Function Previous3DaysDate () >> >> var >> INT Day, >> INT Month, >> INT year >> >> LET Day = StringToInt (SysGetDate ("dd")) >> LET Month = StringToInt (SysGetDate ("MM")) >> LET Year = StringToInt (SysGetDate ("yyyy")) >> >> IF (Day > 3) THEN >> ; if today is > then the 2nd do this to adjust back 3 days >> LET Day = Day - 3 >> Else >> >> ; test to see if today is the 3rd of the month >> IF (Day == 3) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLastDay, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 29 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 3rd day of month >> >> >> ; tests to see if today is the 2nd of the month. >> IF (Day == 2) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast2Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 28 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 2nd day of month >> >> IF (Day == 1) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast3Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 27 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 1st day of month >> >> EndIf >> >> ; all integers now set to the previous day >> >> RETURN (SysGetDate ("MM/dd/yyyy", Month, Day, Year)) >> EndFunction >> >> >> Script WritePrevious3DaysDate () >> >> TypeString (Previous3DaysDate ()) >> >> EnterKey () >> >> EndScript >> >> >> String Function Previous4DaysDate () >> var >> INT Day, >> INT Month, >> INT year >> >> LET Day = StringToInt (SysGetDate ("dd")) >> LET Month = StringToInt (SysGetDate ("MM")) >> LET Year = StringToInt (SysGetDate ("yyyy")) >> >> IF (Day > 4) THEN >> ; if today is > then the 4th do this to adjust back 4 days >> LET Day = Day - 4 >> Else >> >> ; test to see if today is the 4th of the month >> IF (Day == 4) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLastDay, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 29 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 3rd day of month >> >> >> >> ; test to see if today is the 3rd of the month >> IF (Day == 3) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast2Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 28 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 3rd day of month >> >> >> ; tests to see if today is the 2nd of the month. >> IF (Day == 2) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast3Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 27 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 2nd day of month >> >> IF (Day == 1) THEN >> >> LET Day = StringToInt (StringSegment (PreviousMonthLast4Day, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 26 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was 1st day of month >> >> EndIf >> >> ; all integers now set to the previous day >> >> RETURN (SysGetDate ("MM/dd/yyyy", Month, Day, Year)) >> EndFunction >> >> >> Script WritePrevious4DaysDate () >> >> TypeString (Previous4DaysDate ()) >> >> EnterKey () >> >> EndScript >> >> >> Script EnterCurrentDate () >> Var >> String sDate >> Let sDate = SysGetDate ("MM/dd/yyyy") >> TypeString(sDate) >> EnterKey () >> >> EndScript >> >> >> >> *** end copy *** >> >> >> -----Original Message----- >> From: jawsscripts-bounce@xxxxxxxxxxxxx >> [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Paul Magill >> Sent: Friday, February 19, 2010 6:21 AM >> To: jawsscripts@xxxxxxxxxxxxx >> Subject: [jawsscripts] Re: inserting yesterday's date with a script >> >> Hi Jason, >> >> I think the below function may do what you need... >> >> The constanc is required to 'look up' the number of the last day in the >> previous month when the current date is the first day of a month. >> >> - it acts as a list/table, with the first number being the number of days >> in >> December, so when the current month is January, month 1 retrieves the >> last >> day in the first position in the list/table. >> >> If the current date is March the first, then the third position in the >> list is retrieved, 28 days for Febuary. >> >> There is a check for leap years >> >> begin required lines: >> >> >> CONST >> >> PreviousMonthLastDay = "31|31|28|31|30|31|30|31|31|30|31|30" >> >> >> >> String Function PreviousDaysDate () >> >> var >> >> INT Day, >> >> INT Month, >> >> INT year >> >> LET Day = StringToInt (SysGetDate ("dd")) >> >> LET Month = StringToInt (SysGetDate ("MM")) >> >> LET Year = StringToInt (SysGetDate ("yyyy")) >> >> IF (Day > 1) THEN ; not first day of month >> >> LET Day = Day - 1 >> >> ELSE ;day=1, so last day of previous month needed, then previous month >> also >> needed >> >> LET Day = StringToInt (StringSegment (PreviousMonthLastDay, "|", Month)) >> >> LET Month = Month - 1 >> >> IF (Month == 2) && ((Year % 4) == 0) THEN ;is Febuary in a leap year >> >> LET Day = 29 >> >> ENDIF ; is Febuary in a leap year >> >> IF (Month == 0) THEN ; month is January, so December of previous year >> required >> >> LET Month = 12 >> >> LET year = year - 1 >> >> ENDIF ;month was January >> >> ENDIF ; was first day of month, or not >> >> ; all integers now set to the previous day >> >> RETURN (SysGetDate ("MM/dd/yyyy", Month, Day, Year)) >> >> EndFunction >> >> >> >> End required lines. see below for use. >> >> >> >> Script WritePrevious daysDate () >> >> >> >> TypeString (PreviousDaysDate ()) >> >> ; your other lines >> >> EndScript >> >> Regards, >> Paul from Aust >> >> ----- Original Message ----- >> From: "Jason Boston" <jwb3301@xxxxxxx> >> >> >> HI all, >> I work in MS Access much of my day at work and have written a script I >> find >> very useful for pasting in today's date based on the computers system >> date. >> Below is the script I use assigned to the key stroke "ctrl+shift+v". >> However, I would like to create a similar script that pastes in >> yesterday's >> date based on the system date. Since the method I'm using defines the >> system >> date as a string, I can't figure out how to make it go back one day. >> Could >> anyone suggest how to accomplish this with JFW 11 and MS Access? >> >> Here's the script I use for pasting the current date. BTW it works in a >> table, query, or a form. >> >> Script EnterCurrentDate () >> Var >> String sDate >> Let sDate = SysGetDate ("MM/dd/yyyy") >> TypeString(sDate) >> ' next 2 lines takes focus away from current cell and brings it back >> quickly >> so jaws automatically reads you what was just posted. >> {tab} >> ShiftTabKey () >> EndScript >> >> >> __________ >> Visit and contribute to The JAWS Script Repository http://jawsscripts.com >> >> View the list's information and change your settings at >> //www.freelists.org/list/jawsscripts >> >> __________ >> Visit and contribute to The JAWS Script Repository http://jawsscripts.com >> >> View the list's information and change your settings at >> //www.freelists.org/list/jawsscripts >> > > __________ > Visit and contribute to The JAWS Script Repository http://jawsscripts.com > > View the list's information and change your settings at > //www.freelists.org/list/jawsscripts > > > __________ > Visit and contribute to The JAWS Script Repository http://jawsscripts.com > > View the list's information and change your settings at > //www.freelists.org/list/jawsscripts > __________ Visit and contribute to The JAWS Script Repository http://jawsscripts.com View the list's information and change your settings at //www.freelists.org/list/jawsscripts __________ Visit and contribute to The JAWS Script Repository http://jawsscripts.com View the list's information and change your settings at //www.freelists.org/list/jawsscripts