Using the /J (justify) parameter, it is possible to right, center, or left-
justify Fdate's output, truncate it, or pad it with a certain character or
character string.
Note that /J is not a function, but a parameter. The /J parameter may be
used in conjunction with any of Fdate's functions. (It is discussed here,
with the string-handling functions, because that's where it seemed most at
home.)
Justification takes place BEFORE the strings specified on the /P (prefix) and
/S (suffix) parms are added to the output.
The format of the /J parm is:
/J"TP##"
In this example:
- T is a single character indicating the type of justification desired:
- R right
- L left
- C centered
- P is one or more characters specifying the string to be used to
pad the output to the desired length.
- The most common values for this character will be the period
(".") and the blank. In order for a blank to be recognized
as a pad character (and not to be taken as the terminator of
the /J-parm value), the /J-parm value must be enclosed in
single or double quotes, e.g.: /J"C 79"
- The first character of the pad string may be a number, but
no numeric character after the first will be recognized as a
pad character.
- Any numeric character after the first pad character is
assumed to begin the length specification.
- ## is a number that specifies the length of the field within
which justification should take place. This must be a number
between 1 and 240.
- If ## is less than the length of the un-justified output
string, then the un-justified output string will be truncated
to ## characters, starting at the point specified by the
justification type (i.e. at the right, left, or center of the
un-justified output string).
- /J"R08" will right-justify the output, padded
to the left with leading zeroes to a length of 8 characters.
- /J"C- 40" will center-justify the output in a field 40
characters long, with the justification being supplied of the
two characters "- ". Output will look something like this:
- - - - - - my output string - - - - - -
- /J"C-*-40" will center-justify the output in a field 40
characters long, with the justification being supplied of the
3 characters "-*-". Output will look something like this:
-*--*--*--*- my output string -*--*--*--*-
Note that when the pad string is more than one character, output
will be slightly unpredictable, as it will depend on the length of
the pad string, the length of the field in which the output is to
be justified, and the length of the (pre-justification) output
string.
SOME USES FOR THE /J PARM
(Most of these uses are illustrated in HOLIDAYS.BAT, which is included
in the Fdate distribution ZIP file.)
In conjunction with the "echo" function (/Fe), the /J parm can be used
to justify any value that you wish, not just output dates created by
Fdate. Put the value to be justified in the /Q parm. Put a title, for
example, as the value of the /Q parm, and specify center justification,
padded with spaces, to a length of 79 characters (/J"c 79"). This will
display the title, centered on the screen.
If you use the "echo" function and the /J parm, and specify the /Q parm
but do not specify a value for it, then only the pad character will be
displayed. (That is, the null string will be padded with the pad
character to the desired length.)
This is a handy way to draw horizontal lines of dashes,
dots, or any other desired character.
Fdate /FE /Q /JC-79
The /J parm can be used to left-pad a number with zeroes.
.EXAMPLE.....: Many of Fdate's input formats require the year to be in
complete 4-digit CCYY format. If your batch file obtains a
value for YEAR from the user, the user might enter a YEAR
that is less than 1000. You can add leading zeroes to YEAR
by right justifying it, padded it with '0' to a length of 4.
Fdate /Fe /Q%year% /JR04 /vyear
Because /J can be used to truncate a string to a specified length, it
can be used to extract the rightmost, leftmost, or centermost ##
characters of a string.
.EXAMPLE.....: Fdate /Fe /J"C 79" /Q"SCREEN TITLE"
Fdate's output is not put into an environment variable, so it will be
displayed on the screen. This command will echo the string "SCREEN
TITLE" to the screen, centered in a field 79 characters long (that is,
centered on the screen), and padded to the left and right with blanks.
.EXAMPLE.....: Fdate /Fe /J"L.40" /Q"Next report due date" /Vtitle
Fdate /fadd /N60 /Od1 /Q"%title% "
The first command left-justifies "Next report due date" in a
string 40 characters wide, padded to the right with periods, and
puts it into the TITLE environment variable.
In the second step, the TITLE environment variable is used as
the label for a date 60 days in the future. In the second step,
note the space between the end of %title% and the trailing
double-quote. This leaves a nice space between the dot leader
and the date.
.EXAMPLE.....: For more examples, see HOLIDAYS.BAT.