FULLSCREEN CONTENTS Project Home Page
.OTHER_FUNCS.: /J: Justifying Output
.ALIAS.......: JUST_OUT
.DISCUSSION..:
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 AFTER the strings specified on the /P (prefix) and /S (suffix) parms have been added to the output.

The format of the /J parm is: /J"tp##" where

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 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.

EXAMPLES:
/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.

## 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).


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.)

EXAMPLE: 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.


.EXAMPLES:

  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.

  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.

  For more examples, see HOLIDAYS.BAT.

Using the /J (justify) parameter it is possible to right, center, or left-
justify FDATE's output.  See the discussion of JUSTIFYING OUTPUT in the
section on string-handling functions.