Next Friday Function
Next Friday Function
(OP)
Just a bit of old code... to give you the date of the next Friday.
CODE
FUNCTION NEXTFRIDAY PARAMETERS m.MYDATE PRIVATE m.MYDATE IF PCOUNT() < 1 m.MYDATE = DATE() ENDIF m.MYDATE = m.MYDATE + (6-(DOW(m.MYDATE,1)-(INT(DOW(m.MYDATE,1)/6)*7))) RETURN(m.MYDATE)
Regards
Griff
Keep ing
There are 10 kinds of people in the world, those who understand binary and those who don't.
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
One tiny improvement:
Instead of this:
CODE -->
you could do this:
CODE -->
saving a whole line of code.
I would also prefer to lose the mdots on the left of the assignment statements, but I won't open that can of worms again.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Next Friday Function
Yes, I have never really adopted the lparameters approach, and here it is more appropriate than my 'long hand'
The m.dots on the left side may not be necessary, because you can't assign to a field, obviously enough, but I'm happy
with that omission to improve clarity (in my opinion) and the habit of using them reduces the chances of a typing error
creeping in.
Hi Mike Y
I do use Hungarian notation, but only where I am maintaining code developed by someone else - for example I sometimes
customise WestWind utilities and I use the same notation Rick does, again not necessary - but I think it is better
to use 'the same pen' as the originator and not faff about with chalk on his finely crafted calligraphy!
Edit
Of course, these days I'm pretty confident the only person maintaining my code is likely myself... so it's only
public if I present it here.
Regards
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
Chriss
RE: Next Friday Function
Are you thinking if I used the DOW pointing to a Friday base?
CODE
Regards
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
Chriss
RE: Next Friday Function
Next Friday is not equal to today, it has to be at least a day away, otherwise it would be nearest Friday
I started this thread for two reasons, firstly as MY kinda alluded to, in most cases iterating through a loop is probably
less efficient to 'doing the math' - I was reading something recently where even branching on the ELSE was considered
'inferior' - maybe, maybe not. Secondly I wanted to demonstrate that a discussion often generates something actually better
which might be unexpected. NEXTFRIDAY() is nearly forty years old, it isn't pretty, perhaps not as efficient as three people
can make it, but it is - this is key - an example of the shoulders on which we all stand.
We stand on trillions of lines of other peoples code, good, bad or WTF.
I'm pretty happy with that... but I am most certainly going to try and get my grey cells to follow Chris's advice.
Trouble is, they are ... sorry, who are you?
Thank you gentlemen, ahem, people, have a nice evening
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
Anyway, it was never fruitful to show you something, I'll just leave that here and don't bother.
Chriss
RE: Next Friday Function
the likely simplification of NextFriday()
CODE
Faster, more readable, easily modified for NextMonday() etc.
Regards
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
CODE
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
I guess I'm alone in thinking the initial value of a LOCAL var or a parameter should be .NULL., anyway.
I get your point about next, Griff. Just even VFP itself is using REPLACE NEXT 1 for the record itself and not really the next one. I don't assume that was programmed by a non-american. If it comes to language, there's a lot to say about English and Americans about their own language usage, too, dialects and other quirks. Anyway, just spare any more comments on improvements.
Ah, yes, there is a nice read for the weekend, perhaps, by Tamar, about many Foxpro quirks, as well. https://pdfslide.net/documents/visual-foxpro-quirk...
Chriss
RE: Next Friday Function
So test for Empty() instead of pcount()?
CODE
With a local parameter (lParameter) that would work, would it with a private? Not that it is relevant in this example!
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
Thanks for posting that link, Chris. It's something we should all take the time to read.
For the same article in a possibly more user-friendly format, I suggest http://www.tomorrowssolutionsllc.com/ConferenceSes.... The text is identical, but it doesn't have the formatting issues that I see on the PDFSlide site (which might be specific to my system / browser).
While you are at www.tomorrowssolutionsllc.com, take a look at some of Tamar's other articles and conference papers. There's a lot of good stuff there.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Next Friday Function
If you don't pass something to a private paramater, it also becomes .F., that's simple to see just doing it:
CODE
Chriss
RE: Next Friday Function
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
I chose to simplify it to dow(,6) because it was then clear, to me at least, that NextSaturday(), NextTuesday() etc.
would only require modifying that index - maybe ,7) would too - but I haven't tested that.
No disrespect was intended.
As coders we all rely on the people who came before us, who built the OS we work on, the compilers that made that possible,
the people who developed dBase, Fox, Delphi, C, assemblers...
Regards
ing
Griff
Keep
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
There is no place like G28 X0 Y0 Z0
RE: Next Friday Function
Chriss
RE: Next Friday Function
I actually already posted details about how you go about this, just not in this forum. Anyway, why do you even ask? You don't need anybody's enlightenment anyway.
You're sketching scenarios that are not true, that hass actually again become quite unbearable.
Chriss
RE: Next Friday Function
Please if you're sharing my papers, do so from my website: www.tomorrowssolutionsllc.com
Thanks,
Tamar
RE: Next Friday Function
Er ... I presume you mean why has no-one in this forum come up with this version, as the basic algorithm is not exactly new? I've certainly seen it in the past (e.g https://www.theinformationlab.co.uk/2017/05/22/cal...)
RE: Next Friday Function
I just noticed that PDFSLIDE has also taken one of my articles without permission. Does it survive my stealing other people's work? Please do report them, and let us know how you get on. I will do the same.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Next Friday Function
I hate these sites that let just another post a document and don't require them to prove they have IP rights. ScribD had a whole bunch of mine a while back. I actually talked to a lawyer about it, but the feeling was that there wasn't provable harm, so hard to succeed. I check back there periodically to see whether there's more.
Tamar
RE: Next Friday Function
I've faced this situation before. If a polite email to the company doesn't work, my next step has been to contact the abuse administrator, either of the site itself or its hosting company (if any). Every reputable publishing platform or hosting company should have an abuse administrator. You can find their contact details by first determining the site's IP address (for example, by using ping in a command window), and then doing a WhoIs search on that address.
If the offending site is based in the US (but there is often no way of knowing that), you can also take action under the Digital Millennium Copyright Act (DMCA). I've considered doing that a couple of times, but so far it hasn't been necessary.
I hope the above info will be of some help to others who face this situation.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Next Friday Function
It looks like that particular article has now been removed from PDFSLIDE. But I also noticed a copy of the same article on another site. I won't paste the URL directly into this post, as I don't want to give it the benefit of a link, but it is essentially "fdocuments" followed by ".net" adnd then "/document/dev180-visual-foxpro-quirks-tamar-e-foxprodev180-visual-foxpro-quirks-by-tamar" and finally ".html"
I wonder how many more of these pirate sites exist.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Next Friday Function
The one you just sent me to had more of mine, but didn't seem to be monetized. Those are the ones that make me angriest--them charging people to see my work without paying me.
Tamar
RE: Next Friday Function
Mike, you seem to be in a mood for accusations, to say it mildly.
Tamar has very good reasons to be upset as pdfslides advertises with content they just grab from anywhere. They are even as pretending fair use as they point out DMCA. Very clearly just profiting from anyone not caring about earning without much own involvement other than crawling the web.
Chriss
RE: Next Friday Function
CODE -->
Steve
RE: Next Friday Function
I'm not being proud of anything. No idea where you get that idea from. I was merely pointing out that this is not a new algorithm, and providing evidence of that. Sure, your particular implemention differs, but it was unclear that that is all you were claiming.