Author | Topic: DESCEND Function | |
---|---|---|
Jonathan Leeming | DESCEND Function on Wed, 21 Aug 2019 17:05:09 -0600 Hi, I have a need to replicate the descend function outside of Xbase++ (if FoxPro) so I'm trying to create a function which produces the same result as the Xbase++ DESCEND(). I believe I have it figured out for data types, "C","L","N" but not for Dates. My initial attempts with this post resulted in the News Server flagging it as spam and denying the upload so I have taken the original posting and made it a text attachment. I realize this is non-standard but did not know how else to work around the spam flagging. I you could take a moment and read the attached file perhaps you may be able to lend some assistance. Any assistance would be appreciated! Thanks... Jonathan jonathan.leeming@the-family-centre.com Edmonton, Alberta, Canada Descend.txt | |
Jim Lee | Re: DESCEND Function on Thu, 22 Aug 2019 04:10:24 +0200 > I believe I have it figured out for data types, "C","L","N" but not for > Dates. PROCEDURE MAIN LOCAL dDate := DATE() LOCAL dOld := dDate -10 LOCAL dNew := dDate +10 CLS ? dDate ? dOld ? dnew ? "" ? DESCEND(dDate) ? DESCEND(dOld) ? DESCEND(dnew) WAIT RETURN --- Diese E-Mail wurde von AVG auf Viren geprüft. http://www.avg.com | |
Jonathan Leeming | Re: DESCEND Function on Wed, 21 Aug 2019 21:39:33 -0600 On 8/21/2019 8:10 PM, Jim Lee wrote: >> I believe I have it figured out for data types, "C","L","N" but not for >> Dates. > > PROCEDURE MAIN > LOCAL dDate := DATE() > LOCAL dOld := dDate -10 > LOCAL dNew := dDate +10 > > CLS > > ? dDate > ? dOld > ? dnew > ? "" > ? DESCEND(dDate) > ? DESCEND(dOld) > ? DESCEND(dnew) > WAIT > > RETURN > > > > --- > Diese E-Mail wurde von AVG auf Viren geprüft. > http://www.avg.com > Hi Jim, Thanks for the reply. I currently have no problem using the DESCEND() function within Xbase++ but the issue is I'm trying to create a separate function in another language that does not have DESCEND(). The objective is to create some code for a function that will return the same descend values as the Xbase++ DESCEND(). In the descend.txt file I elaborate more and would have included the same in my original message but some phrase in my initial message was flagged as spam so I could not send the message intact. I believe the date needs to be converted to some sort of numerical value that would also handle every 4th year with the extra day as a leap year. In the code from the H_arbour site that I mentioned in my descend.txt attachment there is a "magical" value 5231808. The date value is converted by some yet unknown function and then subtracted from this value (5231808) to get the "Descended" value. Thanks... Jonathan jonathan.leeming@the-family-centre.com Edmonton, Alberta, Canada | |
Andreas Gehrs-Pahl | Re: DESCEND Function on Thu, 22 Aug 2019 07:53:23 -0400 Jonathan, The reason for the Spam Flag, is using that name of the programming language that is a synonym for Port or Haven. Your numbers are off by 30 days, though, at least as far as Xbase++ 2.0.1113 is concerned. The Descend calculation routine is quite simple: 5231808 - DtoJ(Date()) is the same as Descend(Date()) The reverse is: JtoD(5231808 - Descend(Date()) Using today's Date, 08/22/2019, we get the following: dDate := CtoD('08/22/2019') ? Descend(dDate) ==> 2773090 ? 5231808 - DtoJ(dDate) ==> 2773090 ? DtoC(JtoD(5231808 - 2773090)) ==> 08/22/2019 The DtoJ() and JtoD() functions were added to Xbase++ with Version 2.00.832 and don't exist in earlier versions. In VFP, you have the functions SYS(10) -- String from Julian Day Number -- and SYS(11) -- Julian Day Number from Date -- which might return the same values as Xbase++ does, but that would have to be tested. Hope that helps, Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas@AbsoluteSoftwareLLC.com web: http://www.AbsoluteSoftwareLLC.com [F]: https://www.facebook.com/AbsoluteSoftwareLLC | |
Andreas Gehrs-Pahl | Re: DESCEND Function on Thu, 22 Aug 2019 08:49:37 -0400 Jonathan, Luiz Penna just send me an email and pointed out that you don't need the DtoJ() and JtoD() functions to calculate the Descend() value. You can also simply use: nDescend := StoD("96120207") - dDate And the reverse would be: dDate := StoD("96120207") - nDescend And all xBase dialects have the StoD() and/or CtoD() functions. Thanks, Luiz! Hope that helps, Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas@AbsoluteSoftwareLLC.com web: http://www.AbsoluteSoftwareLLC.com [F]: https://www.facebook.com/AbsoluteSoftwareLLC | |
Jonathan Leeming | Re: DESCEND Function on Thu, 22 Aug 2019 09:06:11 -0600 On 8/22/2019 6:49 AM, Andreas Gehrs-Pahl wrote: > Jonathan, > > Luiz Penna just send me an email and pointed out that you don't need the > DtoJ() and JtoD() functions to calculate the Descend() value. > > You can also simply use: > > nDescend := StoD("96120207") - dDate > > And the reverse would be: > > dDate := StoD("96120207") - nDescend > > And all xBase dialects have the StoD() and/or CtoD() functions. > > Thanks, Luiz! > > Hope that helps, > > Andreas > Hi Again, Thanks for passing on Luiz's suggestion!!! Works great. If anyone is interested here is the "final" code in Xbase++ format that should easily convert to VFP: FUNCTION uDescend(xVal) LOCAL xDescend,; nAsc,; nPnt,; cValType cValType := VALTYPE(xVal) IF cValType == "C" xDescend := "" FOR nPnt := 1 TO LEN(xVal) nAsc := 256-ASC(SUBSTR(xVal,nPnt,1)) *nAsc := 255-ASC(xVal[nPnt]) xDescend += CHR(nAsc) NEXT nPnt ELSEIF cValType == "N" xDescend := -xVal ELSEIF cValType == "L" xDescend := ! xVal ELSEIF cValType == "D" *xDescend := 5231808 - DTOJ(xVal) <--- works xDescend := STOD("96120207") - xVal <--- works too! ENDIF RETURN xDescend Thanks to all who lent a hand... both in this news group and private email (Klaus)... This community is great! Thanks again... Jonathan jonathan.leeming@the-family-centre.com Edmonton, Alberta, Canada | |
Jonathan Leeming | Re: DESCEND Function on Thu, 22 Aug 2019 08:51:07 -0600 On 8/22/2019 5:53 AM, Andreas Gehrs-Pahl wrote: > Jonathan, > > The reason for the Spam Flag, is using that name of the programming language > that is a synonym for Port or Haven. > > Your numbers are off by 30 days, though, at least as far as Xbase++ 2.0.1113 > is concerned. > > The Descend calculation routine is quite simple: > > 5231808 - DtoJ(Date()) is the same as Descend(Date()) > > The reverse is: > > JtoD(5231808 - Descend(Date()) > > Using today's Date, 08/22/2019, we get the following: > > dDate := CtoD('08/22/2019') > ? Descend(dDate) ==> 2773090 > ? 5231808 - DtoJ(dDate) ==> 2773090 > > ? DtoC(JtoD(5231808 - 2773090)) ==> 08/22/2019 > > The DtoJ() and JtoD() functions were added to Xbase++ with Version 2.00.832 > and don't exist in earlier versions. > > In VFP, you have the functions SYS(10) -- String from Julian Day Number -- > and SYS(11) -- Julian Day Number from Date -- which might return the same > values as Xbase++ does, but that would have to be tested. > > Hope that helps, > > Andreas > Hi Andreas, I thought that it was the reference to the Port / Haven however after the spam issue I tried a posting using the "forbidden word" in both the header & body to the test section and it worked fine! I first tried your DTOJ() suggestion and it worked great... given the source not a surprise! I was then anticipating the possibility of having to recreate my own DTOJ() function for use within VFP. (continued later in thread). Thanks... Jonathan jonathan.leeming@the-family-centre.com Edmonton, Alberta, Canada |