Post by unknownI have never used the self defined function feature introduced
in one of the later versions of 4dos. The help info is not clear to me as
to how one writes one. I know how to do it in the "nix" shell world.
Could someone do a simple example so I might see how it is constructed?
Let's say for purposes of example one to run a dos program or btm with
arguments.
I assume you've read http://jpsoft.com/help/index.htm?function.htm.
Here are a few functions I use occasionally (they should show as single lines):
:: myMod[n,m] returns m where n%%m returns 0
FUNCTION myMOD=`%@EVAL[((%1-1)%%%2+1)]`
:: DaysOfMonth[validDate] returns number of days in the month
FUNCTION DaysOfMonth=`%@EVAL[42-%@DAY[%@MAKEDATE[%@EVAL[%@DATE[%@YEAR[%@MAKEDATE[%@DATE[%&],4]]-%@MONTH[%&]-1]+41],4]]]`
:: DaysOfMnth[yyyy,mm] returns number of days in the month
FUNCTION DaysOfMnth =`%@EVAL[42-%@DAY[%@MAKEDATE[%@EVAL[%@DATE[%1-%2-1]+41],4]]]`
:: EoMonthN[yyyy,mm] returns the date number of the last day of a month
FUNCTION EoMonthN=`%@DATE[%1-%2-%@DaysOfMnth[%1,%2]]`
:: EoMonthD[yyyy,mm] returns the date string of the last day of a month
FUNCTION EoMonthD=`%@MAKEDATE[%@EoMonthN[%1,%2],4]`
:: LastWDay[yyyy,mm,wd] returns the date for the last weekday [wd 1=Su, 7=Sa] in the month
FUNCTION LastWDay=`%@MAKEDATE[%@EVAL[%@EoMonthN[%1,%2]+%@IF[%3 GT %@DOWI[%@EoMonthD[%1,%2]],%@Eval[%3-%@DOWI[%@EoMonthD[%1,%2]]-7],%@Eval[%3-%@DOWI[%@EoMonthD[%1,%2]]]]],4]`
:: MMM[validDate] returns the 3-letter Monthname
FUNCTION MMM=`%@FIELD[%@MONTH[%&],,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec]`
:: PrevMonth[validDate] returns the argument's previous month
FUNCTION PrevMonth=`%@MONTH[%@MAKEDATE[%@EVAL[%@DATE[%&]-%@DAY[%&]]]]`
:: Win32 associations/filetypes (borrowed from "E. S. (Steve) Fabian")
FUNCTION assoc=`%@word["=",1,%@execstr[assoc %1]]`
FUNCTION ftype=`%@execstr[ftype %1]`
FUNCTION ext_type=`%@ftype[%@assoc[%1]]`
Hope this helps.
--
Michael Bednarek, Brisbane "ONWARD"