Technical Forums (Troubleshooting)

This will provide you easy trouble shooting.

Wednesday, September 28, 2011

Display a printable calendar of the specified year

To display a printable calender of the specified year just copy and save in notepad as clean.bat.
Script :
  1. @ECHO OFF 
  2. :: Windows batch for generating calendars
  3. :: Chances look good for win 2000 and above
  4. IF "%~1"=="/?" (
  5.     ECHO START "%~NX0" WITHOUT ARGUMENTS AND THEN ENTER THE YEAR.
  6.     ECHO "%~NX0" WILL OPEN IN IT'S OWN WINDOW TO AVOID RESIZING
  7.    ECHO AN EXISTING WINDOW.
  8.    ECHO.
  9.    ECHO A SCREEN RESOLUTION AND/OR FONT SIZE THAT CAN DISPLAY
  10.    ECHO CMD WINDOWS OF 96 COLUMNS AND 39 LINES IS REQUIRED.
  11.    ECHO SOME CONFIGURATIONS MAY USE SCROLL BARS TO ACHIEVE
  12.    ECHO THIS.
  13.    EXIT /B
  14. )
  15. :: The current codepage is stored in variable %CodePage%,
  16. :: then changed to 850 to facilitate box drawing characters.....
  17. FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%~A) DO SET CodePage=%%B
  18. CHCP 850 >NUL 2>&1
  19. :: The title can be used to falicitate custom window
  20. :: positioning via the properties menu of "calendars..."
  21. :: /max is used so as much content as possible is visable
  22. :: without moving the window. /max must be removed for
  23. :: custom window positing.....
  24. IF NOT "%~1 %~2"=="WINDOW SIZE" (
  25.     START "CALENDARS..." /MAX CMD /C "%~F0" WINDOW SIZE
  26.     REM Restore the original codepage before exiting.....
  27.     CHCP %CodePage% >NUL 2>&1
  28.     EXIT /B
  29. )
  30. MODE CON:COLS=96 LINES=39
  31. SETLOCAL ENABLEDELAYEDEXPANSION
  32. :loop
  33. FOR %%Z IN (jan feb mar apr may jun jul aug sep oct nov dec year day leap noleap length test) DO SET %%Z=
  34. SET /P year=Enter a year to see it's calendar, or nothing to exitthen press enter:
  35. IF NOT DEFINED year (
  36.     REM Restore the original codepage before exiting.....
  37.     CHCP %CodePage% >NUL 2>&1
  38.     EXIT /B
  39. )
  40. ::Test that the input is only numbers...
  41. SET test=!year!
  42. FOR /%%IN (0 1 9) DO IF DEFINED test SET "test=!test:%%Z=!"
  43. IF DEFINED test CLS&GOTO loop
  44. :zero
  45. IF NOT DEFINED year (
  46.     :error
  47.     cls
  48.     echo The year entered can not be accepted.
  49.     echo.
  50.     pause
  51.     CLS
  52.     GOTO loop
  53. )
  54. :: remove leading zeros, if any...
  55. IF "%year:~0,1%"=="0" SET year=%year:~1%&&GOTO zero
  56. :: The %processor_architecture% test is used to test
  57. :: limits of caculations, if the variable is undefined
  58. :: or unrecognised the test will fall through and complete
  59. :: anyway, if the limit is surpassed this way the results may
  60. :: not be valid. The tested number is ~80% of the limit of the
  61. :: os so that year + year / 4 yields a valid result.
  62. IF /"!processor_architecture!"=="x86" (
  63.     IF !year! gtr 1717986917 GOTO :error
  64. ) else (
  65.     IF NOT "!processor_architecture:64=!"=="!processor_architecture!" (
  66.         IF !year! gtr 7378697629483820645 GOTO :error
  67.     )
  68. )
  69. :: Generate the first day of the year, 0=sun, 1=mon,...,6=sat
  70. :: A 365 day year ofsets by one day, so the next year will start
  71. :: the next day (i.e. 2009 starts on thr and 2010 starts on fri)
  72. :: an extra day must be added for every leapyear. Using modulo
  73. :: 7 on the total of offset days reviels the starting day of the
  74. :: year. one day must also be removed if the year is a leap year
  75. :: because the below will add one for it, the remainder for non
  76. :: leap years is not an issue because set /a only returns whole
  77. :: numbers.
  78. SET /A day=(year + year / 4) - (year / 100 - year / 400)
  79. SET /A leap=year %% 400
  80. SET /A noleap=year %% 100
  81. IF !leap! GTR 0 (
  82.     IF !noleap! NEQ 0 SET /A leap=year %% 4
  83. )
  84. IF %leap%==0 SET /A day-=1
  85. SET /A day%%=7
  86. :: For each year every month is padded to is starting offset
  87. :: with spaces, january has the original offset generated above.
  88. :: each additional offset is generated by adding the total days of
  89. :: the previous month then processing it by modulo 7.
  90. :: The days are stored in a varianle to display later, these variables
  91. :: are padded to 111 characters using spaces for display purposes.
  92. FOR %%IN (jan feb mar apr may jun jul aug sep oct nov dec) DO (
  93.     FOR %%IN (jan mar may jul aug oct dec) DO IF /%%U==%%V SET length=31
  94.     FOR %%IN (apr jun sep nov) DO IF /%%U==%%W SET length=30
  95.     IF /%%U==feb (
  96.         IF !leap!==0 (
  97.             SET length=29
  98.         ) else (
  99.             SET length=28
  100.         )
  101.     )
  102.     FOR /%%IN (1 1 !day!) DO SET "%%U=!%%U!   "
  103.     FOR /%%IN (1 1 !length!) DO (
  104.         IF %%Y lss 10 (
  105.             SET "%%U=!%%U!%%Y  "
  106.         ) else (
  107.             SET "%%U=!%%U!%%Y "
  108.         )
  109.     )
  110.     FOR /%%IN (!length! 1 54) DO IF "!%%U:~110!"=="" SET "%%U=!%%U! "
  111.     SET /A day=^(day + length^) %% 7
  112. )
  113. :test
  114. :: The results are displayed below using substrings of each month's
  115. variable.
  116. cls
  117. TITLE THE CALENDAR FOR THE YEAR OF %YEAR%
  118. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  119. echo. º      JANUARY       º  º      FEBUARY       º  º       MARCH        º  º       APRIL        º
  120. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  121. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  122. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  123. echo. º%JAN:~0,20%º  º%FEB:~0,20%º  º%MAR:~0,20%º  º%APR:~0,20%º
  124. echo. º%JAN:~21,20%º  º%FEB:~21,20%º  º%MAR:~21,20%º  º%APR:~21,20%º
  125. echo. º%JAN:~42,20%º  º%FEB:~42,20%º  º%MAR:~42,20%º  º%APR:~42,20%º
  126. echo. º%JAN:~63,20%º  º%FEB:~63,20%º  º%MAR:~63,20%º  º%APR:~63,20%º
  127. echo. º%JAN:~84,20%º  º%FEB:~84,20%º  º%MAR:~84,20%º  º%APR:~84,20%º
  128. echo. º%JAN:~105%              º  º%FEB:~105%              º  º%MAR:~105%              º  º%APR:~105%              º
  129. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  130. echo.
  131. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  132. echo. º        MAY         º  º        JUNE        º  º        JULY        º  º       AUGUST       º
  133. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  134. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  135. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  136. echo. º%MAY:~0,20%º  º%JUN:~0,20%º  º%JUL:~0,20%º  º%AUG:~0,20%º
  137. echo. º%MAY:~21,20%º  º%JUN:~21,20%º  º%JUL:~21,20%º  º%AUG:~21,20%º
  138. echo. º%MAY:~42,20%º  º%JUN:~42,20%º  º%JUL:~42,20%º  º%AUG:~42,20%º
  139. echo. º%MAY:~63,20%º  º%JUN:~63,20%º  º%JUL:~63,20%º  º%AUG:~63,20%º
  140. echo. º%MAY:~84,20%º  º%JUN:~84,20%º  º%JUL:~84,20%º  º%AUG:~84,20%º
  141. echo. º%MAY:~105%              º  º%JUN:~105%              º  º%JUL:~105%              º  º%AUG:~105%              º
  142. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  143. echo.
  144. echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  145. echo. º     SEPTEMBER      º  º      OCTOBER       º  º      NOVEMBER      º  º      DECEMBER      º
  146. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  147. echo. ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º  ºS  M  T  W  T  F  S º
  148. echo. ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹  ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
  149. echo. º%SEP:~0,20%º  º%OCT:~0,20%º  º%NOV:~0,20%º  º%DEC:~0,20%º
  150. echo. º%SEP:~21,20%º  º%OCT:~21,20%º  º%NOV:~21,20%º  º%DEC:~21,20%º
  151. echo. º%SEP:~42,20%º  º%OCT:~42,20%º  º%NOV:~42,20%º  º%DEC:~42,20%º
  152. echo. º%SEP:~63,20%º  º%OCT:~63,20%º  º%NOV:~63,20%º  º%DEC:~63,20%º
  153. echo. º%SEP:~84,20%º  º%OCT:~84,20%º  º%NOV:~84,20%º  º%DEC:~84,20%º
  154. echo. º%SEP:~105%              º  º%OCT:~105%              º  º%NOV:~105%              º  º%DEC:~105%              º
  155. echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  156. GOTO loop

Thanks.

No comments:

Post a Comment