Author Topic: Calendar Maker  (Read 13742 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #15 on: August 06, 2019, 03:37:28 pm »
Today I made the Calendar Maker even better! I added around 4 holidays and also made it so the user can use the right and left arrow keys to go back and forward in months as you see them. That way if someone needs to know a date on the next month or the last month, they can just use the arrow keys. Or if they are wanting to easily print a few months in a row. :)

(Note: Because I was accidentally using code that masked bmp files to jpg, I changed the program to just save as .bmp and posted it on this forum below this post, so please scroll down, thank you.)

Code: QB64: [Select]
  1. 'This is my very first calendar making program!
  2. 'Thanks to the guys from the QB64.org forum for the help: bplus, SMcNeill, and euklides!
  3. 'This is a freeware program like all my other programs and games, only free.
  4. 'Feel free to use this code in your own programs.
  5. 'Made on Tuesday, August 6, 2019 by Ken G.
  6.  
  7.  
  8. start:
  9. _TITLE "Calendar Maker"
  10. _LIMIT 1000
  11. dd = 0
  12. leap = 0
  13. m = 0
  14. mm = 0
  15. y = 0
  16. yy = 0
  17. w = 0
  18. weekday = 0
  19. days = 0
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21. PRINT "                                  Monthly Calendar Maker"
  22. PRINT "                                        By Ken G."
  23. PRINT "                         With some help from the QB64.org Forum guys!"
  24. PRINT "          This program will make a calendar for the year and month you want."
  25. PRINT "          It will also name some holidays on their days."
  26. PRINT "          This uses the Gregorian Calendar which became common practice in"
  27. PRINT "          England in 1753 and we still use it today."
  28. PRINT "          First make a calender, then if you want to save it as a .jpg file,"
  29. PRINT "          press the 'S' key and it will save it as the month and year for its name."
  30. PRINT "          For example, if you made a calendar for January 2020 and wish to save it,"
  31. PRINT "          press the 'S' key and it will save it as 1-2020.jpg"
  32. PRINT "          If you wish to print your calendar on your printer, press 'P' once."
  33. PRINT "          Feel free to print as many times as you wish. They take up 1 page each."
  34. PRINT "          If you save the .jpg calendar, it will be put in the same directory as this program."
  35. PRINT "          To switch to the last month use the left arrow key, to the next month the right arrow key."
  36. PRINT "          To make a different calendar without saving, press the Space Bar."
  37. PRINT "          Keyboard commands will be listed on the title bar of the window."
  38. again1:
  39. INPUT "          Type the year here (1753-9999): ", y
  40. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again1:
  41. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  42. again2:
  43. INPUT "          Type the month here (1-12): ", m
  44. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  45. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  46.  
  47. calculate:
  48. 'Get the month name.
  49. IF m = 1 THEN month$ = " January"
  50. IF m = 2 THEN month$ = "February"
  51. IF m = 3 THEN month$ = "  March"
  52. IF m = 4 THEN month$ = "  April"
  53. IF m = 5 THEN month$ = "  May"
  54. IF m = 6 THEN month$ = "  June"
  55. IF m = 7 THEN month$ = "  July"
  56. IF m = 8 THEN month$ = " August"
  57. IF m = 9 THEN month$ = "September"
  58. IF m = 10 THEN month$ = " October"
  59. IF m = 11 THEN month$ = "November"
  60. IF m = 12 THEN month$ = "December"
  61.  
  62. 'Calculate to see if it's a Leap Year.
  63. IF m <> 2 THEN GOTO nex:
  64. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  65. IF y / 4 = INT(y / 4) THEN leap = 1
  66. IF y / 100 = INT(y / 100) THEN leap = 0
  67.  
  68. 'Get the number of days for each month.
  69. more:
  70. IF leap = 1 THEN days = 29
  71. IF leap = 0 THEN days = 28
  72. GOTO weekday:
  73. nex:
  74. IF m = 1 THEN days = 31
  75. IF m = 3 THEN days = 31
  76. IF m = 4 THEN days = 30
  77. IF m = 5 THEN days = 31
  78. IF m = 6 THEN days = 30
  79. IF m = 7 THEN days = 31
  80. IF m = 8 THEN days = 31
  81. IF m = 9 THEN days = 30
  82. IF m = 10 THEN days = 31
  83. IF m = 11 THEN days = 30
  84. IF m = 12 THEN days = 31
  85. weekday:
  86.  
  87. 'Set the month, year, and weekday variables to start with.
  88. mm = m
  89. yy = y
  90. GetDay mm, dd, y, weekday
  91.  
  92. 'This section makes the calendar graph.
  93. make:
  94. SCREEN _NEWIMAGE(800, 600, 32)
  95. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  96. _TITLE "Press 'S' to Save, 'P' to Print, Left and Right Arrow Keys To Switch Months, Space Bar For Different One, or 'Esc' to Quit."
  97. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  98. LOCATE 3, 42: PRINT month$; "  "; yy
  99.  
  100. FOR x = 20 TO 780 STEP 108
  101.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  102. FOR z = 100 TO 580 STEP 80
  103.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  104.  
  105. LOCATE 5, 8: PRINT "SUNDAY"
  106. LOCATE 5, 21: PRINT "MONDAY"
  107. LOCATE 5, 34: PRINT "TUESDAY"
  108. LOCATE 5, 47: PRINT "WEDNESDAY"
  109. LOCATE 5, 60: PRINT "THURSDAY"
  110. LOCATE 5, 75: PRINT "FRIDAY"
  111. LOCATE 5, 87: PRINT "SATURDAY"
  112.  
  113. 'Finding Date of Easter
  114. PQA = yy
  115. GOSUB PAQUES
  116. 'month = PQM, day = PQJ, year = PQA
  117.  
  118. 'This section puts the right dates and holidays in the right squares for the calendar.
  119. w = (weekday * 108) + 25
  120. FOR weeky = 110 TO 570 STEP 80
  121.     FOR dayx = w TO 692 STEP 108
  122.         _LIMIT 1000
  123.         dd = dd + 1
  124.         GetDay mm, dd, y, weekday
  125.         dd$ = STR$(dd)
  126.         _FONT 16
  127.         _PRINTSTRING (dayx, weeky), dd$
  128.         _FONT 8
  129.         IF m = 1 AND dd = 1 THEN _PRINTSTRING (dayx + 10, weeky + 60), "New Years":
  130.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  131.         IF m = 2 AND dd = 2 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Groundhog"
  132.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  133.         IF m = 2 AND dd = 14 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  134.         IF m = 3 AND dd = 17 THEN _PRINTSTRING (dayx + 10, weeky + 60), "St. Patrick"
  135.         IF m = PQM AND dd = PQJ THEN _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  136.         IF m = 4 AND dd > 23 AND weekday = 7 THEN _PRINTSTRING (dayx + 25, weeky + 60), "Arbor"
  137.         IF m = 5 AND weekday = 0 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx, weeky + 60), "Armed Forces"
  138.         IF m = 5 AND weekday = 2 AND dd > 24 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  139.         IF m = 6 AND dd = 14 THEN _PRINTSTRING (dayx + 35, weeky + 60), "Flag"
  140.         IF m = 7 AND dd = 4 THEN _PRINTSTRING (dayx, weeky + 60), "Independence"
  141.         IF m = 9 AND weekday = 2 AND dd < 8 THEN _PRINTSTRING (dayx + 25, weeky + 60), "Labor"
  142.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Columbus"
  143.         IF m = 10 AND dd = 31 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  144.         IF m = 11 AND dd = 11 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Veterans"
  145.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN _PRINTSTRING (dayx, weeky + 60), "Thanksgiving"
  146.         IF m = 12 AND dd = 25 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  147.  
  148.         IF dd = days THEN _FONT 16: GOTO more2:
  149.     NEXT dayx
  150.     w = 25
  151. NEXT weeky
  152.  
  153. more2:
  154. _LIMIT 1000
  155. a$ = INKEY$
  156. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  157. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  158. IF a$ = " " THEN GOTO start:
  159. IF a$ = "p" OR a$ = "P" THEN
  160.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  161.     YMAX = _HEIGHT: XMAX = _WIDTH
  162.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  163.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  164.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  165.     _PRINTIMAGE landscape&
  166.  
  167. IF a$ = CHR$(0) + CHR$(77) THEN
  168.     m = m + 1
  169.     IF m > 12 THEN
  170.         m = 1
  171.         yy = yy + 1
  172.     END IF
  173.     y = yy
  174.     IF y > 9999 THEN y = 1753
  175.     dd = 0
  176.     leap = 0
  177.     _DELAY .1
  178.     CLS
  179.     GOTO calculate:
  180. IF a$ = CHR$(0) + CHR$(75) THEN
  181.     m = m - 1
  182.     IF m < 1 THEN
  183.         m = 12
  184.         yy = yy - 1
  185.     END IF
  186.     y = yy
  187.     IF y < 1753 THEN y = 9999
  188.     dd = 0
  189.     leap = 0
  190.     _DELAY .1
  191.     CLS
  192.     GOTO calculate:
  193.  
  194. GOTO more2:
  195.  
  196.  
  197. 'Find the right date for Easter.
  198. PAQUES:
  199. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  200. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  201. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  202. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  203. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  204. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  205.  
  206.  
  207. 'This section saves the calendar to a JPG file along with the SUB at the end of this program.
  208. saving:
  209. mo$ = STR$(m)
  210. mo$ = LTRIM$(RTRIM$(mo$))
  211. year$ = STR$(yy)
  212. year$ = LTRIM$(RTRIM$(year$))
  213. nm$ = mo$ + "-"
  214. nm$ = LTRIM$(RTRIM$(nm$))
  215. nm$ = nm$ + year$
  216. nm$ = LTRIM$(RTRIM$(nm$))
  217. SaveImage 0, nm$ 'saves entire program screen,"
  218. nm2$ = nm$ + ".jpg"
  219. nm2$ = LTRIM$(RTRIM$(nm2$))
  220. PRINT "                                           Saving"
  221. PRINT "                          "; nm2$; " has been saved to your computer."
  222. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  223. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  224. PRINT "                         Goodbye."
  225.  
  226. weekdays:
  227.  
  228. 'This section gets the right weekday.
  229. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  230.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  231.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  232.     century = y MOD 100
  233.     zerocentury = y \ 100
  234.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  235.  
  236. 'This section saves the .jpg picture file.
  237. SUB SaveImage (image AS LONG, filename AS STRING)
  238.     bytesperpixel& = _PIXELSIZE(image&)
  239.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  240.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  241.     x& = _WIDTH(image&)
  242.     y& = _HEIGHT(image&)
  243.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  244.     IF bytesperpixel& = 1 THEN
  245.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  246.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  247.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  248.         NEXT
  249.     END IF
  250.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  251.     lastsource& = _SOURCE
  252.     _SOURCE image&
  253.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  254.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  255.         r$ = ""
  256.         FOR px& = 0 TO x& - 1
  257.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  258.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  259.         NEXT px&
  260.         d$ = d$ + r$ + padder$
  261.     NEXT py&
  262.     _SOURCE lastsource&
  263.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  264.     b$ = b$ + d$ ' total file data bytes to create file
  265.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  266.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  267.     f& = FREEFILE
  268.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  269.     OPEN filename$ + ext$ FOR BINARY AS #f&
  270.     PUT #f&, , b$
  271.     CLOSE #f&
  272.  
« Last Edit: August 12, 2019, 02:10:20 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calendar Maker
« Reply #16 on: August 06, 2019, 05:00:31 pm »
Nice simple improvement!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #17 on: August 06, 2019, 05:20:49 pm »
Thanks B+! This is one of my favorite programs I've ever made. It can be used any day, any month, any year. lol

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Calendar Maker
« Reply #18 on: August 06, 2019, 05:53:06 pm »
Nice? pfftt... It's brilliant! What would make it perfect? If it came in blue.... Well done, SierraKen. Well done!

J
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #19 on: August 06, 2019, 10:48:45 pm »
LOL Thanks Johno! You were probably joking on the blue, but I only have a black and white laser printer so I couldn't test different colors on paper. lol

Offline PauloC

  • Newbie
  • Posts: 2
  • Learning QB64
    • View Profile
    • TRAME Estruturas
Re: Calendar Maker
« Reply #20 on: August 07, 2019, 01:56:28 pm »
This program is very useful to learn QB64. Thank you!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #21 on: August 07, 2019, 04:04:10 pm »
Welcome PauloC!

Offline pforpond

  • Newbie
  • Posts: 76
  • I am me
    • View Profile
Re: Calendar Maker
« Reply #22 on: August 11, 2019, 06:47:12 am »
This is really neato! Love that holidays (albeit US ones) are marked on there. Maybe with some work this could become a full-fledged calendar app with events the user can add themselves, though I'd say adding a bit of colour would be a nice addition too :)
Loading Signature...

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #23 on: August 11, 2019, 12:12:33 pm »
Thanks pforpond! Yeah I only have a black and white printer so I couldn't test printing colors. I might look into making it an events calendar, not sure yet.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Calendar Maker
« Reply #24 on: August 11, 2019, 06:23:05 pm »
Hi
Good Application!
IMHO next step is to colorize holydays and sunday
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #25 on: August 11, 2019, 08:42:45 pm »
Thanks TempodiBasic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #26 on: August 12, 2019, 02:08:07 am »
SmMcNeill told me that the code I was using was actually .bmp pictures with a .jpg ending, so I changed the code on this program to make the calendars save as .bmp instead. I wondered why the picture files were so large lol. So, here is the fixed version. I also removed my Paint Pixels program off my website, for now anyway. The Calendar Maker's fix has been uploaded to my site.

Code: QB64: [Select]
  1. 'This is my very first calendar making program!
  2. 'Thanks to the guys from the QB64.org forum for the help: bplus, SMcNeill, and euklides!
  3. 'This is a freeware program like all my other programs and games, only free.
  4. 'Feel free to use this code in your own programs.
  5. 'Made on Tuesday, August 6, 2019 by Ken G.
  6.  
  7.  
  8. start:
  9. _TITLE "Calendar Maker"
  10. _LIMIT 1000
  11. dd = 0
  12. leap = 0
  13. m = 0
  14. mm = 0
  15. y = 0
  16. yy = 0
  17. w = 0
  18. weekday = 0
  19. days = 0
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21. PRINT "                                  Monthly Calendar Maker"
  22. PRINT "                                        By Ken G."
  23. PRINT "                         With some help from the QB64.org Forum guys!"
  24. PRINT "          This program will make a calendar for the year and month you want."
  25. PRINT "          It will also name some holidays on their days."
  26. PRINT "          This uses the Gregorian Calendar which became common practice in"
  27. PRINT "          England in 1753 and we still use it today."
  28. PRINT "          First make a calendar, then if you want to save it as a .bmp file,"
  29. PRINT "          press the 'S' key and it will save it as the month and year for its name."
  30. PRINT "          For example, if you made a calendar for January 2020 and wish to save it,"
  31. PRINT "          press the 'S' key and it will save it as 1-2020.bmp"
  32. PRINT "          If you wish to print your calendar on your printer, press 'P' once."
  33. PRINT "          Feel free to print as many times as you wish. They take up 1 page each."
  34. PRINT "          If you save the .bmp calendar, it will be put in the same directory as this program."
  35. PRINT "          To switch to the last month use the left arrow key, to the next month the right arrow key."
  36. PRINT "          To make a different calendar without saving, press the Space Bar."
  37. PRINT "          Keyboard commands will be listed on the title bar of the window."
  38. again1:
  39. INPUT "          Type the year here (1753-9999): ", y
  40. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again1:
  41. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  42. again2:
  43. INPUT "          Type the month here (1-12): ", m
  44. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  45. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  46.  
  47. calculate:
  48. 'Get the month name.
  49. IF m = 1 THEN month$ = " January"
  50. IF m = 2 THEN month$ = "February"
  51. IF m = 3 THEN month$ = "  March"
  52. IF m = 4 THEN month$ = "  April"
  53. IF m = 5 THEN month$ = "  May"
  54. IF m = 6 THEN month$ = "  June"
  55. IF m = 7 THEN month$ = "  July"
  56. IF m = 8 THEN month$ = " August"
  57. IF m = 9 THEN month$ = "September"
  58. IF m = 10 THEN month$ = " October"
  59. IF m = 11 THEN month$ = "November"
  60. IF m = 12 THEN month$ = "December"
  61.  
  62. 'Calculate to see if it's a Leap Year.
  63. IF m <> 2 THEN GOTO nex:
  64. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  65. IF y / 4 = INT(y / 4) THEN leap = 1
  66. IF y / 100 = INT(y / 100) THEN leap = 0
  67.  
  68. 'Get the number of days for each month.
  69. more:
  70. IF leap = 1 THEN days = 29
  71. IF leap = 0 THEN days = 28
  72. GOTO weekday:
  73. nex:
  74. IF m = 1 THEN days = 31
  75. IF m = 3 THEN days = 31
  76. IF m = 4 THEN days = 30
  77. IF m = 5 THEN days = 31
  78. IF m = 6 THEN days = 30
  79. IF m = 7 THEN days = 31
  80. IF m = 8 THEN days = 31
  81. IF m = 9 THEN days = 30
  82. IF m = 10 THEN days = 31
  83. IF m = 11 THEN days = 30
  84. IF m = 12 THEN days = 31
  85. weekday:
  86.  
  87. 'Set the month, year, and weekday variables to start with.
  88. mm = m
  89. yy = y
  90. GetDay mm, dd, y, weekday
  91.  
  92. 'This section makes the calendar graph.
  93. make:
  94. SCREEN _NEWIMAGE(800, 600, 32)
  95. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  96. _TITLE "Press 'S' to Save, 'P' to Print, Left and Right Arrow Keys To Switch Months, Space Bar For Different One, or 'Esc' to Quit."
  97. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  98. LOCATE 3, 42: PRINT month$; "  "; yy
  99.  
  100. FOR x = 20 TO 780 STEP 108
  101.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  102. FOR z = 100 TO 580 STEP 80
  103.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  104.  
  105. LOCATE 5, 8: PRINT "SUNDAY"
  106. LOCATE 5, 21: PRINT "MONDAY"
  107. LOCATE 5, 34: PRINT "TUESDAY"
  108. LOCATE 5, 47: PRINT "WEDNESDAY"
  109. LOCATE 5, 60: PRINT "THURSDAY"
  110. LOCATE 5, 75: PRINT "FRIDAY"
  111. LOCATE 5, 87: PRINT "SATURDAY"
  112.  
  113. 'Finding Date of Easter
  114. PQA = yy
  115. GOSUB PAQUES
  116. 'month = PQM, day = PQJ, year = PQA
  117.  
  118. 'This section puts the right dates and holidays in the right squares for the calendar.
  119. w = (weekday * 108) + 25
  120. FOR weeky = 110 TO 570 STEP 80
  121.     FOR dayx = w TO 692 STEP 108
  122.         _LIMIT 1000
  123.         dd = dd + 1
  124.         GetDay mm, dd, y, weekday
  125.         dd$ = STR$(dd)
  126.         _FONT 16
  127.         _PRINTSTRING (dayx, weeky), dd$
  128.         _FONT 8
  129.         IF m = 1 AND dd = 1 THEN _PRINTSTRING (dayx + 10, weeky + 60), "New Years":
  130.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  131.         IF m = 2 AND dd = 2 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Groundhog"
  132.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  133.         IF m = 2 AND dd = 14 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  134.         IF m = 3 AND dd = 17 THEN _PRINTSTRING (dayx + 10, weeky + 60), "St. Patrick"
  135.         IF m = PQM AND dd = PQJ THEN _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  136.         IF m = 4 AND dd > 23 AND weekday = 7 THEN _PRINTSTRING (dayx + 25, weeky + 60), "Arbor"
  137.         IF m = 5 AND weekday = 0 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx, weeky + 60), "Armed Forces"
  138.         IF m = 5 AND weekday = 2 AND dd > 24 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  139.         IF m = 6 AND dd = 14 THEN _PRINTSTRING (dayx + 35, weeky + 60), "Flag"
  140.         IF m = 7 AND dd = 4 THEN _PRINTSTRING (dayx, weeky + 60), "Independence"
  141.         IF m = 9 AND weekday = 2 AND dd < 8 THEN _PRINTSTRING (dayx + 25, weeky + 60), "Labor"
  142.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Columbus"
  143.         IF m = 10 AND dd = 31 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  144.         IF m = 11 AND dd = 11 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Veterans"
  145.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN _PRINTSTRING (dayx, weeky + 60), "Thanksgiving"
  146.         IF m = 12 AND dd = 25 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  147.  
  148.         IF dd = days THEN _FONT 16: GOTO more2:
  149.     NEXT dayx
  150.     w = 25
  151. NEXT weeky
  152.  
  153. more2:
  154. _LIMIT 1000
  155. a$ = INKEY$
  156. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  157. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  158. IF a$ = " " THEN GOTO start:
  159. IF a$ = "p" OR a$ = "P" THEN
  160.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  161.     YMAX = _HEIGHT: XMAX = _WIDTH
  162.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  163.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  164.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  165.     _PRINTIMAGE landscape&
  166.  
  167. IF a$ = CHR$(0) + CHR$(77) THEN
  168.     m = m + 1
  169.     IF m > 12 THEN
  170.         m = 1
  171.         yy = yy + 1
  172.     END IF
  173.     y = yy
  174.     IF y > 9999 THEN y = 1753
  175.     dd = 0
  176.     leap = 0
  177.     _DELAY .1
  178.     CLS
  179.     GOTO calculate:
  180. IF a$ = CHR$(0) + CHR$(75) THEN
  181.     m = m - 1
  182.     IF m < 1 THEN
  183.         m = 12
  184.         yy = yy - 1
  185.     END IF
  186.     y = yy
  187.     IF y < 1753 THEN y = 9999
  188.     dd = 0
  189.     leap = 0
  190.     _DELAY .1
  191.     CLS
  192.     GOTO calculate:
  193.  
  194. GOTO more2:
  195.  
  196.  
  197. 'Find the right date for Easter.
  198. PAQUES:
  199. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  200. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  201. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  202. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  203. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  204. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  205.  
  206.  
  207. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  208. saving:
  209. mo$ = STR$(m)
  210. mo$ = LTRIM$(RTRIM$(mo$))
  211. year$ = STR$(yy)
  212. year$ = LTRIM$(RTRIM$(year$))
  213. nm$ = mo$ + "-"
  214. nm$ = LTRIM$(RTRIM$(nm$))
  215. nm$ = nm$ + year$
  216. nm$ = LTRIM$(RTRIM$(nm$))
  217. SaveImage 0, nm$ 'saves entire program screen,"
  218. nm2$ = nm$ + ".bmp"
  219. nm2$ = LTRIM$(RTRIM$(nm2$))
  220. PRINT "                                           Saving"
  221. PRINT "                          "; nm2$; " has been saved to your computer."
  222. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  223. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  224. PRINT "                         Goodbye."
  225.  
  226. weekdays:
  227.  
  228. 'This section gets the right weekday.
  229. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  230.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  231.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  232.     century = y MOD 100
  233.     zerocentury = y \ 100
  234.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  235.  
  236. 'This section saves the .bmp picture file.
  237. SUB SaveImage (image AS LONG, filename AS STRING)
  238.     bytesperpixel& = _PIXELSIZE(image&)
  239.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  240.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  241.     x& = _WIDTH(image&)
  242.     y& = _HEIGHT(image&)
  243.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  244.     IF bytesperpixel& = 1 THEN
  245.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  246.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  247.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  248.         NEXT
  249.     END IF
  250.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  251.     lastsource& = _SOURCE
  252.     _SOURCE image&
  253.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  254.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  255.         r$ = ""
  256.         FOR px& = 0 TO x& - 1
  257.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  258.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  259.         NEXT px&
  260.         d$ = d$ + r$ + padder$
  261.     NEXT py&
  262.     _SOURCE lastsource&
  263.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  264.     b$ = b$ + d$ ' total file data bytes to create file
  265.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  266.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  267.     f& = FREEFILE
  268.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  269.     OPEN filename$ + ext$ FOR BINARY AS #f&
  270.     PUT #f&, , b$
  271.     CLOSE #f&
  272.  
  273.  





Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calendar Maker
« Reply #27 on: September 11, 2019, 12:07:37 pm »
Thanks Ken lines 140-158 came in handy for me updating my calendar maker for holidays.

For Easter I found and modified a little SUB:
Code: QB64: [Select]
  1. _TITLE "Test Easter calc 1899 to 2100" 'b+ mod 2019-09-11 checked OK for next decade
  2. DIM yr AS INTEGER, rMonth AS INTEGER, rDay AS INTEGER, m$
  3. PRINT "Easter by the method of Carter (SmallBASIC):"
  4.     INPUT "(0 quits, enter year 1900 to 2099 > "; yr
  5.     IF yr = 0 THEN PRINT "Goodbye": END
  6.     IF yr >= 1900 OR yr <= 2099 THEN
  7.         Easter yr, rMonth, rDay
  8.         IF rMonth = 3 THEN m$ = "March" ELSE m$ = "April"
  9.         PRINT "Easter for year"; yr; "is "; m$; rDay
  10.     ELSE
  11.         PRINT "1899 < year < 2100": BEEP
  12.     END IF
  13.     PRINT
  14.  
  15. SUB Easter (givenYear AS INTEGER, rtnMonth AS INTEGER, rtnDay AS INTEGER)
  16.     ' Easter date calculator by Carter from SmallBASIC FLTK pack 1 of 3 given for Easter
  17.     ' This one is restricted to years 1900 to 2099
  18.     DIM tb AS INTEGER, td AS INTEGER, te AS INTEGER
  19.     tb = 225 - 11 * (givenYear MOD 19)
  20.     td = (tb - 21) MOD 30 + 21
  21.     te = (givenYear + givenYear \ 4 + td + 1) MOD 7
  22.     rtnDay = td + 7 - te
  23.     IF rtnDay < 32 THEN
  24.         rtnMonth = 3
  25.     ELSE
  26.         rtnDay = rtnDay - 31
  27.         rtnMonth = 4
  28.     END IF
  29.  

So in Maker, Easter setup:
Code: QB64: [Select]
  1. y = 2020 'free calendar
  2. DIM EasterMonth AS INTEGER, EasterDay AS INTEGER
  3. Easter y, EasterMonth, EasterDay
  4.  

Check and print for Easter:
Code: QB64: [Select]
  1.         IF m = EasterMonth AND dd = EasterDay THEN
  2.             _PRINTSTRING (col * boxW + sideMar + 5, (row + 1) * boxH + yTopGrid - 5 - CH2), "        Easter"
  3.         END IF
  4.  

I've also added Mother's Day and Father's Day
Code: QB64: [Select]
  1. IF m = 5 AND weekday = 1 AND dd > 7 AND dd < 15 THEN S$ = S$ + " Mother's Day"
  2. IF m = 6 AND weekday = 1 AND dd > 14 AND dd < 22 THEN S$ = S$ + " Father's Day"
  3.  
and for 2020: Daylight Savings Start and End, and US Election Day

PLUS Birthdays of my family :)
« Last Edit: September 11, 2019, 12:13:33 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker
« Reply #28 on: September 13, 2019, 06:17:52 pm »
Welcome B+! And thank you for the Mother's Day and Father's Day code! I just added it. It already had Easter on mine. That's all I will add I think. I haven't programmed in a couple weeks or so (besides your code here). I just can't think of anything original to make anymore. A lot of my programs are my own versions of stuff that has already been made and I'm like, "If people can find a better version of this somewhere else, why make a lesser version?" But I really like what I've made so far, so maybe sometime soon I'll think of something else. 

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calendar Maker
« Reply #29 on: September 13, 2019, 08:39:47 pm »
Hi Ken,

Sounds like good time to practice basics, arrays, subs and functions. When you don't have a particular app demanding to get working you can experiment with these main tools. A good game to play is take some code and see if you can do the same thing in less lines.

Another thing to work on is your tool box, subs and functions you can use in future apps.