Author Topic: Calendar Maker 2  (Read 3644 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Calendar Maker 2
« on: December 29, 2021, 06:54:27 pm »
I made Calendar Maker back in 2019 here with the help of you guys. So today I decided to update it with a version 2 that lets people print out an entire year at one time. I've tested it and it works fine. There's no pictures for the calendar but you can always draw on it or put them back in the printer the right way and print something on the backs using a different program. I just figured that it's that time of year and some of you might want a printed out calendar for next year. After printed, add one blank piece of paper on top of it so you can hold up January if you put it on the wall. Stapling and punching the hole can be a bit tricky, so take your time on that if you do it. With this program you can also print one month at a time. It has most of the U.S. holidays. I didn't add a way to add any text to it when you print the whole year at once, but it does add some usual holidays. If you want to add text to a day, or even save a month as a BMP file, then you will have to do each month individually. Enjoy, and Happy New Years!

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, euklides, and TempodiBasic!
  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. 'This version has the ability to add info or holidays to dates.
  6. 'Made on Thursday, September 19, 2019 by Ken G.
  7. 'Calendar Maker 2 version made on Dec. 29, 2021.
  8.  
  9. start:
  10. _Title "Calendar Maker"
  11. _Limit 1000
  12. Dim newinfo$(50)
  13. Dim dayinfo(50)
  14. holidays = 0
  15. dd = 0
  16. leap = 0
  17. m = 0
  18. mm = 0
  19. y = 0
  20. yy = 0
  21. w = 0
  22. weekday = 0
  23. days = 0
  24.  
  25. Screen _NewImage(800, 600, 32)
  26. Print "                                  Monthly Calendar Maker 2"
  27. Print "                                        By Ken G."
  28. Print "                         With some help from the QB64.org Forum guys!"
  29. Print "          This program will make a calendar for the year and month you want."
  30. Print "          It will also name some U.S. holidays on their dates if you choose that."
  31. Print "          You also can add holidays or info to any day you wish with up to 12"
  32. Print "          letters, numbers, symbols, or spaces."
  33. Print "          This uses the Gregorian Calendar which became common practice in"
  34. Print "          England in 1753 and we still use it today."
  35. Print "          First make a calendar, then if you want to save it as a .bmp file,"
  36. Print "          press the 'S' key and it will save it as the month and year for its name."
  37. Print "          For example, if you made a calendar for January 2020 and wish to save it,"
  38. Print "          press the 'S' key and it will save it as 1-2020.bmp"
  39. Print "          If you wish to print your calendar on your printer, press 'P' once."
  40. Print "          Feel free to print as many times as you wish. They take up 1 page each."
  41. Print "          If you save the .bmp calendar, it will be put in the same directory as this program."
  42. Print "          To switch to the last month use the left arrow key, to the next month the right arrow key."
  43. Print "          Switching months with the arrow keys will not save your new date info if you come back."
  44. Print "          To make a different calendar without saving, press the Space Bar."
  45. Print "          Keyboard commands will be listed on the title bar of the window."
  46. Print "          Added Feature: Print a whole year at once, without saving, with some holidays."
  47. Print "          You can draw or print something on the back of each month using a different program,"
  48. Print "          staple them together, punch a hole, and hang it on the wall!"
  49. loops = 0
  50. Input "          Would you like to print a whole year? (Y/N):", wholeyear$
  51. If Left$(wholeyear$, 1) = "y" Or Left$(wholeyear$, 1) = "Y" Then m = 0: loops = 1
  52.  
  53. again1:
  54. Input "          Type the year here (1753-9999): ", y
  55. If y <> Int(y) Then Print "Cannot use decimals, try again.": GoTo again1:
  56. If y < 1753 Or y > 9999 Then Print "The year can only be between 1753 and 9999, try again.": GoTo again1:
  57. If loops = 1 Then
  58.     year = y
  59.     holidays = 1
  60.     Print
  61.     Input "          Press Enter to print whole year.", ent$
  62.     GoTo calculate:
  63. again2:
  64. Input "          Type the month here (1-12): ", m
  65. If m <> Int(m) Then Print "Cannot use decimals, try again.": GoTo again2:
  66. If m < 1 Or m > 12 Then Print "1-12 only, try again.": GoTo again2:
  67. Input "          Do you want U.S. holidays added (Y/N)?", hol$
  68. If Left$(hol$, 1) = "y" Or Left$(hol$, 1) = "Y" Then holidays = 1
  69. Input "          Do you want to add your own holidays or info (Y/N)?", adding$
  70.  
  71. 'It loops here 12 times when printing an entire year.--------------------------------------------------------
  72. calculate:
  73. If loops = 1 Then m = m + 1
  74. If m > 12 Then loops = 0: GoTo start:
  75. dd = 0
  76. leap = 0
  77. mm = 0
  78. w = 0
  79. yy = 0
  80. weekday = 0
  81. days = 0
  82. info = 0
  83. infos = 0
  84. 'Get the month name.
  85. If m = 1 Then month$ = " January"
  86. If m = 2 Then month$ = "February"
  87. If m = 3 Then month$ = "  March"
  88. If m = 4 Then month$ = "  April"
  89. If m = 5 Then month$ = "  May"
  90. If m = 6 Then month$ = "  June"
  91. If m = 7 Then month$ = "  July"
  92. If m = 8 Then month$ = " August"
  93. If m = 9 Then month$ = "September"
  94. If m = 10 Then month$ = " October"
  95. If m = 11 Then month$ = "November"
  96. If m = 12 Then month$ = "December"
  97.  
  98. 'Calculate to see if it's a Leap Year.
  99. If m <> 2 Then GoTo nex:
  100. If y / 400 = Int(y / 400) Then leap = 1: GoTo more:
  101. If y / 4 = Int(y / 4) Then leap = 1
  102. If y / 100 = Int(y / 100) Then leap = 0
  103.  
  104. 'Get the number of days for each month.
  105. more:
  106. If leap = 1 Then days = 29
  107. If leap = 0 Then days = 28
  108. GoTo weekday:
  109. nex:
  110. If m = 1 Then days = 31
  111. If m = 3 Then days = 31
  112. If m = 4 Then days = 30
  113. If m = 5 Then days = 31
  114. If m = 6 Then days = 30
  115. If m = 7 Then days = 31
  116. If m = 8 Then days = 31
  117. If m = 9 Then days = 30
  118. If m = 10 Then days = 31
  119. If m = 11 Then days = 30
  120. If m = 12 Then days = 31
  121. weekday:
  122.  
  123. 'Set the month, year, and weekday variables to start with.
  124. mm = m
  125. yy = y
  126. GetDay mm, dd, y, weekday
  127. If loops = 1 Then y = year
  128.  
  129.  
  130. If Left$(adding$, 1) = "y" Or Left$(adding$, 1) = "Y" Then GoSub adding:
  131. adding$ = ""
  132.  
  133. 'This section makes the calendar graph.
  134. make:
  135. Screen _NewImage(800, 600, 32)
  136. Line (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  137. _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."
  138. Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  139. Locate 3, 42: Print month$; "  "; yy
  140.  
  141. For x = 20 To 780 Step 108
  142.     Line (x, 100)-(x, 580), _RGB32(0, 0, 0)
  143. For z = 100 To 580 Step 80
  144.     Line (16, z)-(780, z), _RGB32(0, 0, 0)
  145.  
  146. Locate 5, 8: Print "SUNDAY"
  147. Locate 5, 21: Print "MONDAY"
  148. Locate 5, 34: Print "TUESDAY"
  149. Locate 5, 47: Print "WEDNESDAY"
  150. Locate 5, 60: Print "THURSDAY"
  151. Locate 5, 75: Print "FRIDAY"
  152. Locate 5, 87: Print "SATURDAY"
  153.  
  154. 'Finding Date of Easter
  155. PQA = yy
  156. GoSub PAQUES
  157. 'month = PQM, day = PQJ, year = PQA
  158.  
  159. 'This section puts the right dates and holidays in the right squares for the calendar.
  160. w = (weekday * 108) + 25
  161. For weeky = 110 To 570 Step 80
  162.     For dayx = w To 692 Step 108
  163.         _Limit 1000
  164.         dd = dd + 1
  165.         GetDay mm, dd, y, weekday
  166.         If loops = 1 Then y = year
  167.         If weekday = 1 Then GoSub coloring:
  168.         If weekday <> 1 Then Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  169.         dd$ = Str$(dd)
  170.         _Font 8
  171.         If dd = dayinfo(infos) Then
  172.             GoSub coloring:
  173.             i = Len(newinfo$(infos))
  174.             If i < 8 Then ii = 25
  175.             If i > 7 And i < 12 Then ii = 11
  176.             If i > 11 And i < 14 Then ii = 5
  177.             If i > 13 Then ii = 2
  178.             _PrintString (dayx + ii, weeky + 20), newinfo$(infos)
  179.             infos = infos + 1
  180.             ye = 1
  181.         End If
  182.         If holidays = 0 Then GoTo skip:
  183.         If m = 1 And dd = 1 Then
  184.             GoSub coloring:
  185.             _PrintString (dayx + 15, weeky + 60), "New Years"
  186.         End If
  187.         If m = 1 And weekday = 2 And dd > 14 And dd < 22 Then
  188.             GoSub coloring:
  189.             _PrintString (dayx + 25, weeky + 60), "MLK Jr."
  190.         End If
  191.         If m = 2 And dd = 2 Then
  192.             GoSub coloring:
  193.             _PrintString (dayx + 13, weeky + 60), "Groundhog"
  194.         End If
  195.         If m = 2 And weekday = 2 And dd > 14 And dd < 22 Then
  196.             GoSub coloring:
  197.             _PrintString (dayx + 10, weeky + 60), "Presidents"
  198.         End If
  199.         If m = 2 And dd = 14 Then
  200.             GoSub coloring:
  201.             _PrintString (dayx + 10, weeky + 60), "Valentines"
  202.         End If
  203.         If m = 3 And dd = 17 Then
  204.             GoSub coloring:
  205.             _PrintString (dayx + 5, weeky + 60), "St. Patrick"
  206.         End If
  207.         If m = PQM And dd = PQJ Then
  208.             GoSub coloring:
  209.             _PrintString (dayx + 25, weeky + 60), "Easter"
  210.         End If
  211.         If m = 4 And dd > 23 And weekday = 7 Then
  212.             GoSub coloring:
  213.             _PrintString (dayx + 25, weeky + 60), "Arbor"
  214.         End If
  215.         If m = 5 And weekday = 0 And dd > 14 And dd < 22 Then
  216.             GoSub coloring:
  217.             _PrintString (dayx + 2, weeky + 60), "Armed Forces"
  218.         End If
  219.         If m = 5 And weekday = 2 And dd > 24 Then
  220.             GoSub coloring:
  221.             _PrintString (dayx + 15, weeky + 60), "Memorial"
  222.         End If
  223.         If m = 5 And weekday = 1 And dd > 7 And dd < 15 Then
  224.             GoSub coloring:
  225.             _PrintString (dayx + 2, weeky + 60), "Mother's Day"
  226.         End If
  227.         If m = 6 And weekday = 1 And dd > 14 And dd < 22 Then
  228.             GoSub coloring:
  229.             _PrintString (dayx + 2, weeky + 60), "Father's Day"
  230.         End If
  231.         If m = 6 And dd = 14 Then
  232.             GoSub coloring:
  233.             _PrintString (dayx + 35, weeky + 60), "Flag"
  234.         End If
  235.         If m = 7 And dd = 4 Then
  236.             GoSub coloring:
  237.             _PrintString (dayx + 2, weeky + 60), "Independence"
  238.         End If
  239.         If m = 9 And weekday = 2 And dd < 8 Then
  240.             GoSub coloring:
  241.             _PrintString (dayx + 27, weeky + 60), "Labor"
  242.         End If
  243.         If m = 10 And dd > 9 And dd < 16 And weekday = 2 Then
  244.             GoSub coloring:
  245.             _PrintString (dayx + 17, weeky + 60), "Columbus"
  246.         End If
  247.         If m = 10 And dd = 31 Then
  248.             GoSub coloring:
  249.             _PrintString (dayx + 15, weeky + 60), "Halloween"
  250.         End If
  251.         If m = 11 And dd = 11 Then
  252.             GoSub coloring:
  253.             _PrintString (dayx + 19, weeky + 60), "Veterans"
  254.         End If
  255.         If m = 11 And dd > 21 And dd < 29 And weekday = 5 Then
  256.             GoSub coloring:
  257.             _PrintString (dayx + 2, weeky + 60), "Thanksgiving"
  258.         End If
  259.         If m = 12 And dd = 25 Then
  260.             GoSub coloring:
  261.             _PrintString (dayx + 15, weeky + 60), "Christmas"
  262.         End If
  263.         skip:
  264.         ye = 0
  265.         _Font 16
  266.         _PrintString (dayx, weeky), dd$
  267.         _Font 8
  268.         If dd = days Then _Font 16: GoTo more2:
  269.     Next dayx
  270.     w = 25
  271. Next weeky
  272.  
  273. more2:
  274. _Limit 100
  275. a$ = InKey$
  276. If a$ = Chr$(27) Then Cls: Print: Print: Print "Goodbye.": End
  277. If a$ = "s" Or a$ = "S" Then GoTo saving:
  278. If a$ = " " Then GoTo start:
  279. If a$ = "p" Or a$ = "P" Or loops = 1 Then
  280.     _Delay 2
  281.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  282.     YMAX = _Height: XMAX = _Width
  283.     landscape& = _NewImage(YMAX, XMAX, 32)
  284.     _MapTriangle (XMAX, 0)-(0, 0)-(0, YMAX), 0 To(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  285.     _MapTriangle (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 To(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  286.     _PrintImage landscape&
  287.  
  288. If a$ = Chr$(0) + Chr$(77) And loops = 0 Then
  289.     m = m + 1
  290.     If m > 12 Then
  291.         m = 1
  292.         yy = yy + 1
  293.     End If
  294.     y = yy
  295.     If y > 9999 Then y = 1753
  296.     dd = 0
  297.     leap = 0
  298.     _Delay .1
  299.     Cls
  300.     GoTo calculate:
  301. If a$ = Chr$(0) + Chr$(75) And loops = 0 Then
  302.     m = m - 1
  303.     If m < 1 Then
  304.         m = 12
  305.         yy = yy - 1
  306.     End If
  307.     y = yy
  308.     If y < 1753 Then y = 9999
  309.     dd = 0
  310.     leap = 0
  311.     _Delay .1
  312.     Cls
  313.     GoTo calculate:
  314. If loops = 1 Then _Delay 1: Cls: GoTo calculate:
  315. GoTo more2:
  316.  
  317. adding:
  318. If loops = 1 Then Return
  319. add:
  320. olddayinfo = dayinfo(info)
  321. info = info + 1
  322. infos = 1
  323. adding2:
  324. If info > days Then Print "You have reached the maximum amount of holidays or info for this month.": Input "Press enter to create calendar.", pe$: Return
  325. Print "Your dates must go in order here."
  326. Print "for example, you cannot put info for day 15 and then put info for day 1."
  327. Print "They must all follow from smallest number to highest number or it will tell you to start over again."
  328. Print "Also, you cannot change a day by doing it over again, so if you mess up, create a new month."
  329. Print info; ". ";
  330. Input "Which day of the month for new holiday or information: ", dayinfo(info)
  331. If dayinfo(info) > days Then Print "That day is not on this calendar, try again.": GoTo adding2:
  332. If dayinfo(info) < 1 Then Print "You cannot type a date less than 1, try again.": GoTo adding2:
  333. If dayinfo(info) <> Int(dayinfo(info)) Then Print "You cannot type a decimal for a date, try again.": GoTo adding2:
  334. If dayinfo(info) < olddayinfo Then
  335.     Print
  336.     Print "You have put a date before your previous one which cannot work, start over from your first date."
  337.     For dl = 1 To info
  338.         newinfo$(dl) = ""
  339.         dayinfo(dl) = 0
  340.     Next dl
  341.     olddayinfo = 0
  342.     info = 0
  343.     GoTo add:
  344. adding3:
  345. Print "Type up to 12 letters, numbers, or spaces that will be put for that day."
  346. Input "->", newinfo$(info)
  347. infoamount = Len(newinfo$(info))
  348. If infoamount > 12 Then Print "Too long, try again.": GoTo adding3:
  349. If infoamount < 1 Then Print "Nothing typed, try again.": GoTo adding3:
  350. Input "Do you want to add more (Y/N):", yn$
  351. If Left$(yn$, 1) = "y" Or Left$(yn$, 1) = "Y" Then GoTo adding:
  352.  
  353. 'Color all Sundays and holidays
  354. coloring:
  355. If ye = 1 Then Return
  356. Line (dayx - 4, weeky - 9)-(dayx + 102, weeky + 68), _RGB32(255, 255, 127), BF: Color _RGB32(0, 0, 0), _RGB32(255, 255, 127)
  357.  
  358.  
  359. 'Find the right date for Easter.
  360. PAQUES:
  361. PQM = Int(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = Int(((PQA / 19 - Int(PQA / 19)) + .001) * 19)
  362. PQ2 = Int(PQM / 4): PQ3 = Int(((PQM / 4) - PQ2 + .001) * 4): PQ4 = Int((8 + PQM) / 25)
  363. PQ5 = Int((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - Int(PQ4)
  364. PQ4 = Int(PQ4 * 30): PQ5 = Int(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  365. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - Int(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  366. PQ6 = Int(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = Int(PQ2): PQJ = Int((PQ2 - PQM + .001) * 31 + 1)
  367.  
  368.  
  369. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  370. saving:
  371. If loops = 1 Then GoTo more2:
  372. mo$ = Str$(m)
  373. mo$ = LTrim$(RTrim$(mo$))
  374. year$ = Str$(yy)
  375. year$ = LTrim$(RTrim$(year$))
  376. nm$ = mo$ + "-"
  377. nm$ = LTrim$(RTrim$(nm$))
  378. nm$ = nm$ + year$
  379. nm$ = LTrim$(RTrim$(nm$))
  380. SaveImage 0, nm$ 'saves entire program screen,"
  381. nm2$ = nm$ + ".bmp"
  382. nm2$ = LTrim$(RTrim$(nm2$))
  383. Print "                                           Saving"
  384. Print "                          "; nm2$; " has been saved to your computer."
  385. Input "                         Do you wish to make another calendar (Y/N)"; ag$
  386. If Left$(ag$, 1) = "y" Or Left$(ag$, 1) = "Y" Then GoTo start:
  387. Print "                         Goodbye."
  388.  
  389. weekdays:
  390.  
  391. 'This section gets the right weekday.
  392. Sub GetDay (mm, dd, y, weekday) 'use 4 digit year
  393.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  394.     If mm < 3 Then y = y - 1
  395.     If mm < 3 Then mm = mm + 12
  396.     century = y Mod 100
  397.     zerocentury = y \ 100
  398.     weekday = (dd + Int(13 * (mm + 1) / 5) + century + Int(century / 4) + Int(zerocentury / 4) + 5 * zerocentury) Mod 7
  399.  
  400. 'This section saves the .bmp picture file.
  401. Sub SaveImage (image As Long, filename As String)
  402.     bytesperpixel& = _PixelSize(image&)
  403.     If bytesperpixel& = 0 Then Print "Text modes unsupported!": End
  404.     If bytesperpixel& = 1 Then bpp& = 8 Else bpp& = 24
  405.     x& = _Width(image&)
  406.     y& = _Height(image&)
  407.     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)
  408.     If bytesperpixel& = 1 Then
  409.         For c& = 0 To 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  410.             cv& = _PaletteColor(c&, image&) ' color attribute to read.
  411.             b$ = b$ + Chr$(_Blue32(cv&)) + Chr$(_Green32(cv&)) + Chr$(_Red32(cv&)) + Chr$(0) 'spacer byte
  412.         Next
  413.     End If
  414.     Mid$(b$, 11, 4) = MKL$(Len(b$)) ' image pixel data offset(BMP header)
  415.     lastsource& = _Source
  416.     _Source image&
  417.     If ((x& * 3) Mod 4) Then padder$ = String$(4 - ((x& * 3) Mod 4), 0)
  418.     For py& = y& - 1 To 0 Step -1 ' read JPG image pixel color data
  419.         r$ = ""
  420.         For px& = 0 To x& - 1
  421.             c& = Point(px&, py&) 'POINT 32 bit values are large LONG values
  422.             If bytesperpixel& = 1 Then r$ = r$ + Chr$(c&) Else r$ = r$ + Left$(MKL$(c&), 3)
  423.         Next px&
  424.         d$ = d$ + r$ + padder$
  425.     Next py&
  426.     _Source lastsource&
  427.     Mid$(b$, 35, 4) = MKL$(Len(d$)) ' image size(BMP header)
  428.     b$ = b$ + d$ ' total file data bytes to create file
  429.     Mid$(b$, 3, 4) = MKL$(Len(b$)) ' size of data file(BMP header)
  430.     If LCase$(Right$(filename$, 4)) <> ".bmp" Then ext$ = ".bmp"
  431.     f& = FreeFile
  432.     Open filename$ + ext$ For Output As #f&: Close #f& ' erases an existing file
  433.     Open filename$ + ext$ For Binary As #f&
  434.     Put #f&, , b$
  435.     Close #f&
  436.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Calendar Maker 2
« Reply #1 on: December 29, 2021, 07:00:56 pm »
Thanks Ken, my own calendar maker has been nicely improved from our discussion back then.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker 2
« Reply #2 on: December 29, 2021, 07:29:23 pm »
That's great! It was a bit tricky doing this today. The old calendar weeks code would mess up the variables for some reason so I added the year variable to switch it back when the old code's SUB was finished. Now it works fine. I tried other ways too inside the SUB but nothing worked that way. I know learning why things don't work is the best way, but sometimes that just can't be done. So I find work-arounds. :)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Calendar Maker 2
« Reply #3 on: December 30, 2021, 04:47:22 pm »
I forgot to say that you can also look at any year, or print any year, or save any month of any year as a BMP picture file, from the start of the Gregorian Calendar (1753 A.D.) to 9999 A.D. When you look at months, you can use the right and left arrow keys to flip through the different months and years.

Also, if anyone wishes to see the conversations we had making the first version, go here: https://qb64forum.alephc.xyz/index.php?topic=1569.0