Menu From the News
Page 4
Index
Index Page 3 | Page 5 | Nomenclature


     CD %TEMP%
     Add 1
     Sub 1. Count down
     Switching.bat
     Nested.bat
     ErLevHEX.bat Returns Errorlevel as HEX.
     B-Levels.bat Set Errorlevel / Get Bennylevel.
     HEXtoDEC.bat A small hex2dec converter.
     Multi.Batch  ASCII table. Useful when working in DOS with colors.






CD %TEMP%.

The TEMP environment can simply be set to a drive letter followed by a colon
or a drive specification followed by a colon with one or more directories.

Won't work:            CD %temp%\

Work (sometimes):      FOR %%v in (: d) do c%%v %temp%\

This solution was hard to find (I used an hour) and it is tested in both old
DOS 6.22 and in Win 98:

   IF not (%temp%)==() FOR %%v in (%temp%.\ CD) do %%v %temp%.



Add 1

Purpose: Repeat something without using third-party file(s).

   @echo off
   SET I000=
   SET I00=
   SET I0=
   SET I=
   SET X=%I%
   SET j=
:Loop
   IF (%X%)==() SET X=0
   ECHO SHIFT>       %temp%.\1.bat
   ECHO SET X=%%%X%>>%temp%.\1.bat
   CALL %temp%.\1.bat 1 2 3 4 5 6 7 8 9 0
   SET I%j%=%X%
   IF NOT %X%==0 FOR %%! in (GOTO:Next SET) do %%! j=
   SET j=%j%0
   IF %j%== 0 FOR %%! in (GOTO:Loop SET) do %%! X=%I0%
   IF %j%==00 FOR %%! in (GOTO:Loop SET) do %%! X=%I00%
              FOR %%! in (GOTO:Loop SET) do %%! X=%I000%
:Next
   ECHO %I000%%I00%%I0%%I%
   IF NOT 9==%I000%%I00%%I0%%I% FOR %%! in (GOTO:Loop SET) do %%! X=%I%
   FOR %%! in (X I I0 I00 I000) do SET %%!=
   DEL %temp%.\1.bat

EXIT. Notes:

      Loops per second:
1__________________________________________|                       86,0
2___________________________________________________|             104,0
3_____________________________________________________|           108,0
4_________________________________________________________|       116,5
      (a long line meeans fast syntax).

1. "SHIFT"  and "FOR %%X in (0 %X%) do SET X=%%X".
2. No Shift and "FOR %%X in (0 %X%) do SET X=%%X".
3. No Shift and "IF (%X%)==() SET X=0" (instead of the above FOR loop).
4. No Shift and without the line (FOR or IF) setting X=0 if X is blank.

   2, 3 and 4 requires "CD %TEMP%." and "ECHO SET X=%%%X%> " instead of
       "ECHO SET X=%%%X%>>" and
       "CALL 1 2 3 4 5 6 7 8 9 0  [filename must be 1.bat]", instead of
       "CALL %temp%.\1.bat 1 2 3 4 5 6 7 8 9 0".

   4 requires "I000, I00, I0 and I" are set to zero (or another value),
   and that you prefix the exit value with zeros "IF NOT 0009" (instead
   of "IF NOT 9").

   Running on a RAM drive without antivirus can also speed up the loop.


Sub 1. Count down (543 to 525)

The following is also (as the above), a result of my baching this week, i.e.
both the change TEMP tricks and my previours experience from page 3 is used:

   @echo off
   SET I000=
   SET  I00=5
   SET   I0=4
   SET    I=3
   ECHO %I000%%I00%%I0%%I%
   IF not (%temp%)==() FOR %%v in (%temp%.\ CD) do %%v %temp%.
   SET X=%I%
   SET j=
:Loop
   ECHO SET X=%%%X%>9.bat
   CALL 9 0 1 2 3 4 5 6 7 8
   SET I%j%=%X%
   IF NOT %X%==9 FOR %%! in (GOTO:Next SET) do %%! j=
   SET j=%j%0
   IF %j%== 0 FOR %%! in (GOTO:Loop SET) do %%! X=%I0%
   IF %j%==00 FOR %%! in (GOTO:Loop SET) do %%! X=%I00%
              FOR %%! in (GOTO:Loop SET) do %%! X=%I000%
:Next
   ECHO %I000%%I00%%I0%%I%
   IF NOT 525==%I000%%I00%%I0%%I% FOR %%! in (GOTO:Loop SET) do %%! X=%I%
   FOR %%! in (X I I0 I00 I000) do SET %%!=
   DEL 9.bat


EXIT. -- Btw. here's another method:

   IF %X%==8 SET X=7
   IF %X%==9 SET X=8
   IF %X%==0 SET X=9, and so...

OR
   echo EXIT|%comspec%/kPROMPT SET V9=8$_SET V8=7$_SET V7=6$_SET V6=5$_SET V
5=4$_SET V4=3$_SET V3=2$_SET V2=1$_SET V1=0$_SET V0=9$_:>9.bat
   CALL 9.bat

:Loop from here
   %comspec%/cECHO SET X=%%V%X%%%>9.bat
   CALL 9.bat

Maybe continued including speed test and STRINGS.COM, etc...


Switching.bat

   @echo off
   CHOICE/n/c'01  ÿ Set X to 0 or 1? % [margin]%
   FOR %%e in (0 1) do if errorlevel }%%e SET X=%%e
         ECHO.  (X) = (%X%)
                 FOR %%%X% in (1 0) do IF NOT %%%X%==%X% SET X=%%%X%
                 :: Or FOR %%X in (0 1) do IF NOT %%X==%X% SET X=%%X
         ECHO.  (X) = (%X%)
   FOR %%%X% in (1 0) do IF NOT %%%X%==%X% ECHO.  X was %%%X% but is now %X%

 Notes:
 The character of ASCII value 255 (FFh) is used to get a margin (a prefix of
 space) and two percent with a space between, % %, is used at the end of the
 CHOICE syntax.


Nested.bat

@ECHO OFF
ECHO. Input a two digit number N: (between 00 and 20),
CHOICE/n/c'''''''''0123456789>NUL
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel 1%%n SET N=%%n
CHOICE/n/c'0123456789 %N%
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel }%%n SET N=%N%%%n

SET NESTED=|ECHO %N%'|CHOICE/c'0123456789>NUL
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel }%%n SET B=%%n
:Repeat
ECHO..|CHOICE/c'''%NESTED%.>NUL
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF errorlevel Y%B%%%n SET L=%B%%%n
ECHO. %L% NESTED = %NESTED%
SET NESTED=%NESTED%#
IF NOT (%L%)==(%N%) GOTO Repeat

ECHO.  Ruler:    0         1         2         3         4         5
ECHO.            01234567890123456789012345678901234567890123456789012
FOR %%n in (N B L NESTED) do SET %%n=


ErLevHEX.bat

  This batch file returns the Errorlevel parameter as a two digit HEX number

  @ECHO OFF
  SET B=F
  FOR %%! IN (0 A B C D E F G H I J K L M N O) DO IF ERRORLEVEL %%!0000 SET 
A=%%!
  FOR %%! in (E D C B A @) DO IF NOT ERRORLEVEL %A%00I%%! SET B=%%!
  IF @==%B% FOR %%! in (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %A%000%%! SET 
B=%%!
  ECHO %A%'|CHOICE/c'0ABCDEFGHI'''''''JKLMNO>NUL
  FOR %%! in (1 2 3 4 5 6 7 8 9 A B C D E F) DO IF ERRORLEVEL }%%! SET A=%%!
  ECHO. Errorlevel %A%%B%h
  FOR %%! in (A B) do SET %%!=


B-Levels.bat

  Examples:
  Input 1 (or 257...) and the ERRORLEVEL would be set to one.
  The Exit code (ERRORLEVEL) set is displayed both dec & hex.

  To get the ASCII value of a normal character (a character that usual
  works in DOS/Batch files), just prefix the input with a lowercase H.

  This batch file is 70 lines & 2319 bytes. Please unwrap line num 62.

  @ECHO OFF
  IF NOT %1!== ! FOR %%c in (SET GOTO) do %%c Y=%1
  ECHO: Input,
  FC/n/Lb1 NUL CON|FIND "1">%temp%.\~.bat
  ECHO::EXIT|%COMSPEC%/kPROMPT e102'SET Y='$_w$_q|DEBUG %temp%.\~.bat>NUL
  CALL %temp%.\~.bat
  :Y [jumped, (external value)].
  SET N=40
  SET D=0
  IF ERRORLEVEL % (odd, not even.)%%Y%p000128 SET D=1
  SET H=3
  SET X=F
  GOTO N
  :0000
  IF 0==%X% FOR %%! in (GOTO:N SET) do %%! X=2
  IF 2==%X% FOR %%! in (GOTO:N SET) do %%! X=4
  IF 4==%X% FOR %%! in (GOTO:N SET) do %%! X=6
  IF 6==%X% FOR %%! in (GOTO:N SET) do %%! X=8
  IF 8==%X% FOR %%! in (GOTO:N SET) do %%! X=A
  IF C==%X% FOR %%! in (GOTO:N SET) do %%! X=E
  SET X=C
  GOTO N
  :0001
  IF 1==%X% FOR %%! in (SET GOTO:N) do %%! X=3
  IF 3==%X% FOR %%! in (SET GOTO:N) do %%! X=5
  IF 5==%X% FOR %%! in (SET GOTO:N) do %%! X=7
  IF 7==%X% FOR %%! in (SET GOTO:N) do %%! X=9
  IF 9==%X% FOR %%! in (SET GOTO:N) do %%! X=B
  IF D==%X% SET X=F
  IF B==%X% SET X=D
  :N
  ECHO a>               %temp%.\~.bat
  ECHO mov ax,4c%H%%X%>>%temp%.\~.bat
  ECHO int 21>>         %temp%.\~.bat
  ECHO.>>               %temp%.\~.bat
  ECHO g>>              %temp%.\~.bat
  DEBUG   >NUL<         %temp%.\~.bat
  IF NOT ERRORLEVEL %Y% GOTO:000%N% SET Y=00000000
  IF !==!%D% GOTO End
  IF 10==%N% GOTO Add
  SET N=10
  FOR %%! in (0 4 8) do IF ERRORLEVEL %(3F 7F BF)%%%!0063 SET H=%%!
  GOTO N
  :00010
  FOR %%! in (1 2 3,5 6 7,9) do IF ERRORLEVEL %()%%%!0255 SET H=%%!
  FOR %%! in (  A B,D E F, ) do IF ERRORLEVEL %()%%%!0143 SET H=%%!
  FOR %%! in (   3 7 B F   ) do IF %H% == %%! GOTO Add
  GOTO N
  :00040
  @                              SET H=7
  IF     ERRORLEVEL %(7F...)%127 SET H=B
  IF NOT ERRORLEVEL %(...7F)%128 GOTO N
  SET N=10
  SET H=C
  GOTO N
  :Add
  SET N=%D%
  SET D=
  SET X=%N%
  GOTO N
  :End
  FOR %%! in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
) do IF ERRORLEVEL %%!0 SET D=%%!
  FOR %%! in (0 1 2 3 4 5 6 7 8 9) do IF ERRORLEVEL %D%%%! SET D=%D%%%!
  IF ERRORLEVEL * FOR %%! in (0 1 2 3 4 5) do IF ERRORLEVEL I%%! SET D=25%%!
  ECHO.
  ECHO.
  ECHO.        IF ERRORLEVEL %Y%  equivalent: IF ERRORLEVEL %D% (%H%%X% Hex)
  FOR %%! in (Y N D H X) do SET %%!=
  DEL %temp%.\~.bat
  IF %1!== ! FOR %%! in (ECHO ECHO PAUSE CLS) do %%!.

  :------------------------
  : Links: [Usenet].
  : Notes:
  : You can substitute the SET Y=00000000 with ECHO: OOPS!: (no value in Y).
  : You can use the: %()% in line number 45 or/and 46 to write your comments
  : about the Errorlevel is tested: (0F 1F 2F,4F 5F 6F,8F)/(9F AF,CF DF EF).
  : I have add the above comments because: I'm not completly convinced about
  : that everyone can see that 9Fh is equivalent (170000 +143) -256n = 159d.
  : Hint: Input: 170143 or A0143 (ASCII value of A is 65 and 65 -48 is 17d).
  : More notes about how it works shouldn't be necessary, just run the batch
  : in your head. I have done a lot about writing it simple as possible, so,
  : the file should be worth a closer look: (a tool written to programmers),
  : but if you just use it to convert RGB code to hex numbers would be okay.
  :-)

  Extra:

  Modifications:
  Adding five lines after line number 31: (Label N):

  :N
if not d''%n% ==%t% call echo.
set t= d''%n%
echo...>%temp%.\~.bat
echo exit|%comspec% /k prompt e100' %h%%x%'%t%$_w$_q|debug %temp%.\~.bat>nul
type %temp%.\~.bat

  Notice that you can modify the first two lines of the above:
  i.e.: substitute the (d) in (d''%n%) with either (a), or (0)
  like this:
                if not a''%n% ==%t% call echo.
                set t= a''%n%
         OR:
                if not 0''%n% ==%t% call echo.
                set t= 0''%n%

  About the third line: "ECHO...>%temp%.\~.bat":

  The number of dots in "ECHO..." matching the length of data i.e. number of
  characters in ' %h%%x%' = 3, (REM. that the RCX register would be 4 byte),
  so, the variable named N is only used to determine when ECHO. (in the CALL
  ECHO.) should be done.

  A compact and alternative one lines, could be written something like this:

  :N                                  (d)
echo exit|%comspec%/kprompt e0' %h%%x%'d$_rcx$_4$_w0$_q|debug con>nul


  Benny Pedersen,
  PS.: You can put the following two lines after line number 1: (@ECHO OFF):

echo exit|%comspec% /k prompt fb800:00 Lfa0 20 2f$_q|debug>nul
echo exit|%comspec% /k prompt fb800:a0 L0a0 20 f8$_q|debug>nul

  or use a compact version:

  @ECHO OFF
echo exit|%comspec%/kprompt fb800:0Lfa0' /'$_fb800:a0La0' 'f8$_q|debug>nul

  TIPS: If you do an exploration of the suggested modifications, then use an
        input of a high number such as 255, so, you'll get a better overview
        of any differences.

  BTW.: Please don't use this one :-)

  @ECHO OFF
  echo exit|%comspec%/kprompt fb800:0Lfa0 2 cf$_q|debug>nul
  choice/c$/t$,2>nul
  cls


Hex2dec

@ MODE Co40
@ ECHO EXIT|%COMSPEC%/kPROMPT fB800:0L7D0' /'$_fB800:50L50'_'78$_q|debug>NUL
::Before executing this batch program, please unwrap 3 lines (num 4, 6 & 8:)
@% 1% ECHO OFF
%  2% ECHO: Input Hex (two digits:)
%  3% CHOICE/n/c~0123456789~~~~~~~ABCDEF>NUL
%  4%FOR %%! in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do IF errorlevel 77%%! SET
 X=%%!
%  5% CHOICE/n/c~0123456789~~~~~~~ABCDEF %X%
%  6%FOR %%! in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do IF errorlevel 77%%! SET
 X=%X%%%!
%  7%ECHO EXIT|%COMSPEC%/kPROMPT a$_mov ax,4c%X%$_int 21$_$_g$_|debug|SET X=
%  8%FOR %%! in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 24) do IF ERRORLEVEL %%!0 SET X=%%!
%  9% FOR %%! in (0 1 2 3 4 5 6 7 8 9) do IF ERRORLEVEL %X%%%! SET X=%X%%%!
% 10% FOR %%! in (0 1 2 3 4 5) do IF ERRORLEVEL 25%%! SET X=25%%!
% 11% ECHO: %X% Dec


Colors

::@  MULTI.BAT: (64 lines including this).
::@         All tables in one file. Preview of a GIF file is available at:
::@         http://users.cybercity.dk/~bse26236/batutil/help/how/multi.gif
::@         Converting HEX to DEC, DEC to HEX. Get the ASCII values
::@         in both HEX and DEC or get the code to make all colors.
::@         This batch file maybe handy for tuning the monitor RGB,
::@         the colour temperature and the contrast for Batch work.
::@         Benny Pedersen,
::@         PS. Try substituting all '?' with '[' and 'o' with 'k'.
@echo off
@if exist %0.bat %0.bat
find<%0 "@"/v|debug>nul
@goto eof
fB800:21EL44' p0p1p2p3p4p5p6p7p8p9pApBpCpDpEpFp'
eB800:2B8' '7'1'7 2 0A'0p'F 00 F 01 F 02 F 03 F 04 F 05 F 06 F 07 F 08 F 09
eB800:2D4 2 0A F 0B F 0C F 0D F 0E F 0F'0p'00'?'01'o'02'?'03'o'04'?'05'o'
eB800:2EE 06'?'07'o'08'?'09'o'0A'?'0B'o'0C'?'0D'o'0E'?'0F'o'
eB800:358' '7'2'7 2 14'1p'F 10 F 11 F 12 F 13 2 14 F 15 F 16 F 17 F 18 F 19
eB800:374 F 1A F 1B F 1C F 1D 2 1E F 1F'1p'10'o'11'?'12'o'13'?'14'o'15'?'
eB800:38E 16'o'17'?'18'o'19'?'1A'o'1B'?'1C'o'1D'?'1E'o'1F'?'
eB800:3F8' '7'4'7 2 28'2p'F 20 F 21 F 22 F 23 F 24 F 25 F 26 F 27 2 28 F 29
eB800:414 F 2A F 2B F 2C F 2D F 2E F 2F'2p'20'?'21'o'22'?'23'o'24'?'25'o'
eB800:42E 26'?'27'o'28'?'29'o'2A'?'2B'o'2C'?'2D'o'2E'?'2F'o'
eB800:498' '7'5'7 2 32'3p'F 30 F 31 2 32 F 33 F 34 F 35 F 36 F 37 F 38 F 39
eB800:4B4 F 3A F 3B 2 3C F 3D F 3E F 3F'3p'30'o'31'?'32'o'33'?'34'o'35'?'
eB800:4CE 36'o'37'?'38'o'39'?'3A'o'3B'?'3C'o'3D'?'3E'o'3F'?'
eB800:538' '7'7'7 2 46'4p'F 40 F 41 F 42 F 43 F 44 F 45 2 46 F 47 F 48 F 49
eB800:554 F 4A F 4B F 4C F 4D F 4E F 4F'4p'40'?'41'o'42'?'43'o'44'?'45'o'
eB800:56E 46'?'47'o'48'?'49'o'4A'?'4B'o'4C'?'4D'o'4E'?'4F'o'
eB800:5D8' '7'8'7 2 50'5p'2 50 F 51 F 52 F 53 F 54 F 55 F 56 F 57 F 58 F 59
eB800:5F4 2 5A F 5B F 5C F 5D F 5E F 5F'5p'50'o'51'?'52'o'53'?'54'o'55'?'
eB800:60E 56'o'57'?'58'o'59'?'5A'o'5B'?'5C'o'5D'?'5E'o'5F'?'
eB800:678'1'7'0'7 2 64'6p'F 60 F 61 F 62 F 63 2 64 F 65 F 66 F 67 F 68 F 69
eB800:694 F 6A F 6B F 6C F 6D 2 6E F 6F'6p'60'?'61'o'62'?'63'o'64'?'65'o'
eB800:6AE 66'?'67'o'68'?'69'o'6A'?'6B'o'6C'?'6D'o'6E'?'6F'o'
eB800:718'1'7'2'7 2 78'7p'F 70 F 71 F 72 F 73 F 74 F 75 F 76 F 77 2 78 F 79
eB800:734 F 7A F 7B F 7C F 7D F 7E F 7F'7p'70'o'71'?'72'o'73'?'74'o'75'?'
eB800:74E 76'o'77'?'78'o'79'?'7A'o'7B'?'7C'o'7D'?'7E'o'7F'?'
eB800:7B8'1'7'3'7 2 82'8p'F 80 F 81 2 82 F 83 F 84 F 85 F 86 F 87 F 88 F 89
eB800:7D4 F 8A F 8B 2 8C F 8D F 8E F 8F'8p'80'?'81'o'82'?'83'o'84'?'85'o'
eB800:7EE 86'?'87'o'88'?'89'o'8A'?'8B'o'8C'?'8D'o'8E'?'8F'o'
eB800:858'1'7'5'7 2 96'9p'F 90 F 91 F 92 F 93 F 94 F 95 2 96 F 97 F 98 F 99
eB800:874 F 9A F 9B F 9C F 9D F 9E F 9F'9p'90'o'91'?'92'o'93'?'94'o'95'?'
eB800:88E 96'o'97'?'98'o'99'?'9A'o'9B'?'9C'o'9D'?'9E'o'9F'?'
eB800:8F8'1'7'6'7 2 A0'Ap'2 A0 F A1 F A2 F A3 F A4 F A5 F A6 F A7 F A8 F A9
eB800:914 2 AA F AB F AC F AD F AE F AF'Ap'A0'?'A1'o'A2'?'A3'o'A4'?'A5'o'
eB800:92E A6'?'A7'o'A8'?'A9'o'AA'?'AB'o'AC'?'AD'o'AE'?'AF'o'
eB800:998'1'7'8'7 2 B4'Bp'F B0 F B1 F B2 F B3 2 B4 F B5 F B6 F B7 F B8 F B9
eB800:9B4 F BA F BB F BC F BD 2 BE F BF'Bp'B0'o'B1'?'B2'o'B3'?'B4'o'B5'?'
eB800:9CE B6'o'B7'?'B8'o'B9'?'BA'o'BB'?'BC'o'BD'?'BE'o'BF'?'
eB800:A38'2'7'0'7 2 C8'Cp'F C0 F C1 F C2 F C3 F C4 F C5 F C6 F C7 2 C8 F C9
eB800:A54 F CA F CB F CC F CD F CE F CF'Cp'C0'?'C1'o'C2'?'C3'o'C4'?'C5'o'
eB800:A6E C6'?'C7'o'C8'?'C9'o'CA'?'CB'o'CC'?'CD'o'CE'?'CF'o'
eB800:AD8'2'7'1'7 2 D2'Dp'F D0 F D1 2 D2 F D3 F D4 F D5 F D6 F D7 F D8 F D9
eB800:AF4 F DA F DB 2 DC F DD F DE F DF'Dp'D0'o'D1'?'D2'o'D3'?'D4'o'D5'?'
eB800:B0E D6'o'D7'?'D8'o'D9'?'DA'o'DB'?'DC'o'DD'?'DE'o'DF'?'
eB800:B78'2'7'3'7 2 E6'Ep'F E0 F E1 F E2 F E3 F E4 F E5 2 E6 F E7 F E8 F E9
eB800:B94 F EA F EB F EC F ED F EE F EF'Ep'E0'?'E1'o'E2'?'E3'o'E4'?'E5'o'
eB800:BAE E6'?'E7'o'E8'?'E9'o'EA'?'EB'o'EC'?'ED'o'EE'?'EF'o'
eB800:C18'2'7'4'7 2 F0'Fp'2 F0 F F1 F F2 F F3 F F4 F F5 F F6 F F7 F F8 F F9
eB800:C34 2 FA F FB F FC F FD F FE F FF'Fp'F0'o'F1'?'F2'o'F3'?'F4'o'F5'?'
eB800:C4E F6'o'F7'?'F8'o'F9'?'FA'o'FB'?'FC'o'FD'?'FE'o'FF'?'
q
:eof


-Top- Page 3 | Page 5 | Nomenclature