QB64.org Forum

Active Forums => Programs => Topic started by: SierraKen on August 05, 2019, 01:55:20 am

Title: Calendar Maker
Post by: SierraKen on August 05, 2019, 01:55:20 am
Here is the Calendar Maker program I've worked on in the last couple days. I'm 99.9% sure it is finished. I know I could have done it differently and not used LOCATE on my numbers and holidays, but with the math I used and the loops, and all the hard work I did to make things fit in the boxes, I'm just going to leave it like this. If you use it enough, you might come across holiday names that don't look centered at all, but I'm just going to leave it like this. This is the first calendar program I've ever made. Thank you to B+, SMcNeill, and euklides for your help. I added your names to the code at the top. I find it pretty neat how you can use this program to go from the mid-1700's to 9999. You can also make one of the month you were born. You also can save the calendars as JPG pictures, with a different name for every month and year. I say in the welcome screen that you can use Windows Paint or any other graphics program to print it out. I printed out the month I was born. :) You also can use this program to use it as a tool to print them out and write tiny reminders for certain days. I thought about adding that to the program, but I don't know enough about making data files to do that. I would end up making a separate data file for every single reminder and that would be a mess. Plus I feel pretty confident that this is complete for me and I finally made a neat calendar maker. Of course anyone can use the code and expand on it from here if they wish. But please try it out. I suggest putting it in a separate directory so you can find your calendar JPG files easy. For example, the picture file for January 2000 would be made like this: 1-2000.jpg. I did it that way so they would line up in the Windows directory in order. Have fun with it!
P..S. Also, I know there's ways to print out pictures, and probably even rotate them first before you print them, but I haven't looked too much into that and I'm very cautious about printing graphics with my programs because twice so far I've printed 2 of them where it made the entire papers black, which is so much toner wasted in the printer.

(Note: As usual, this first paste isn't the best, so scroll down, thanks.)

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, B+, 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 Sunday, August 4, 2019 by Ken G.
  6. '
  7. _TITLE "Calendar Maker"
  8. start:
  9. dd = 0
  10. leap = 0
  11. SCREEN _NEWIMAGE(800, 600, 32)
  12. PRINT "                                     Monthly Calendar Maker"
  13. PRINT "                                           By Ken G."
  14. PRINT "             This program will make a calendar for the year and month you want."
  15. PRINT "             It will also name some holidays on their days."
  16. PRINT "             This uses the Gregorian Calendar which became common practice in"
  17. PRINT "             England in 1753."
  18. PRINT "             First make a calender, then if you want to save it as a .jpg file,"
  19. PRINT "             press the 'S' key and it will save it as the month and year for its name."
  20. PRINT "             For example, if you made a calendar for January 2020 and wish to save it,"
  21. PRINT "             press the 'S' key and it will save it as 1-2020.jpg"
  22. PRINT "             Feel free to use a different program to change the picture as you wish and"
  23. PRINT "             also print it with a printer, with Windows Paint or something else."
  24. PRINT "             The .jpg calendar picture will be saved in the same directory as this program."
  25. PRINT "             To make a new calendar without saving, press the Space Bar."
  26. PRINT "             Keyboard commands will be listed on the title bar of the window."
  27. again1:
  28. INPUT "             Type the year here (1753-9999): ", y
  29. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  30. again2:
  31. INPUT "             Type the month here (1-12): ", m
  32. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  33.  
  34. 'Get the month name.
  35. IF m = 1 THEN month$ = " January"
  36. IF m = 2 THEN month$ = "February"
  37. IF m = 3 THEN month$ = "  March"
  38. IF m = 4 THEN month$ = "  April"
  39. IF m = 5 THEN month$ = "  May"
  40. IF m = 6 THEN month$ = "  June"
  41. IF m = 7 THEN month$ = "  July"
  42. IF m = 8 THEN month$ = " August"
  43. IF m = 9 THEN month$ = "September"
  44. IF m = 10 THEN month$ = " October"
  45. IF m = 11 THEN month$ = "November"
  46. IF m = 12 THEN month$ = "December"
  47.  
  48. 'Calculate to see if it's a Leap Year.
  49. IF m <> 2 THEN GOTO nex:
  50. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  51. IF y / 4 = INT(y / 4) THEN leap = 1
  52. IF y / 100 = INT(y / 100) THEN leap = 0
  53.  
  54. 'Get the number of days for each month.
  55. more:
  56. IF leap = 1 THEN days = 29
  57. IF leap = 0 THEN days = 28
  58. GOTO weekday:
  59. nex:
  60. IF m = 1 THEN days = 31
  61. IF m = 3 THEN days = 31
  62. IF m = 4 THEN days = 30
  63. IF m = 5 THEN days = 31
  64. IF m = 6 THEN days = 30
  65. IF m = 7 THEN days = 31
  66. IF m = 8 THEN days = 31
  67. IF m = 9 THEN days = 30
  68. IF m = 10 THEN days = 31
  69. IF m = 11 THEN days = 30
  70. IF m = 12 THEN days = 31
  71. weekday:
  72.  
  73. 'Set the month, year, and weekday variables to start with.
  74. mm = m
  75. yy = y
  76. GetDay mm, dd, y, weekday
  77.  
  78. 'This section makes the calendar graph.
  79. make:
  80. _TITLE "Press 'S' to Save, Space Bar to make another calendar, or 'Esc' to quit."
  81. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  82. COLOR _RGB(0, 0, 0), _RGB(255, 255, 255)
  83. LOCATE 3, 42: PRINT month$; "  "; yy
  84.  
  85. FOR x = 20 TO 780 STEP 108
  86.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  87. FOR z = 100 TO 580 STEP 80
  88.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  89.  
  90. LOCATE 5, 8: PRINT "SUNDAY"
  91. LOCATE 5, 21: PRINT "MONDAY"
  92. LOCATE 5, 34: PRINT "TUESDAY"
  93. LOCATE 5, 47: PRINT "WEDNESDAY"
  94. LOCATE 5, 60: PRINT "THURSDAY"
  95. LOCATE 5, 75: PRINT "FRIDAY"
  96. LOCATE 5, 87: PRINT "SATURDAY"
  97.  
  98. 'Finding Date of Easter
  99. PQA = yy
  100. GOSUB PAQUES
  101. 'month = PQM, day = PQJ, year = PQA
  102.  
  103. 'This section puts the right dates and holidays in the right squares for the calendar.
  104. w = (weekday * 13) + 8
  105. FOR week = 8 TO 59 STEP 5
  106.     FOR day = w TO 91 STEP 13
  107.         dd = dd + 1
  108.         GetDay mm, dd, y, weekday
  109.         IF weekday = 0 THEN LOCATE week, day + 2: PRINT dd
  110.         IF weekday = 1 THEN LOCATE week, day - 2: PRINT dd
  111.         IF weekday = 2 THEN LOCATE week, day - 2: PRINT dd
  112.         IF weekday = 3 THEN LOCATE week, day - 1: PRINT dd
  113.         IF weekday = 4 THEN LOCATE week, day: PRINT dd
  114.         IF weekday > 4 THEN LOCATE week, day + 2: PRINT dd
  115.         IF m = 1 AND dd = 1 THEN LOCATE week + 2, day - 1: PRINT "New Years": LOCATE week + 3, day: PRINT "Day"
  116.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN LOCATE week + 2, day - 1: PRINT "MLK Jr.": LOCATE week + 3, day: PRINT "Day"
  117.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN LOCATE week + 2, day + 3: PRINT "Pres.": LOCATE week + 3, day + 3: PRINT "Day"
  118.         IF m = 2 AND dd = 14 THEN LOCATE week + 2, day + 3: PRINT "Val.": LOCATE week + 3, day + 3: PRINT "Day"
  119.         IF m = PQM AND dd = PQJ THEN LOCATE week + 2, day - 1: PRINT "Easter"
  120.         IF m = 5 AND weekday = 2 AND dd > 24 THEN LOCATE week + 2, day - 1: PRINT "Mem.": LOCATE week + 3, day - 1: PRINT "Day"
  121.         IF m = 7 AND dd = 4 THEN LOCATE week + 2, day - 1: PRINT "Independ.": LOCATE week + 3, day + 2: PRINT "Day"
  122.         IF m = 9 AND weekday = 2 AND dd < 8 THEN LOCATE week + 2, day - 2: PRINT "Labor Day"
  123.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN LOCATE week + 2, day - 1: PRINT "Columbus": LOCATE week + 3, day: PRINT "Day"
  124.         IF m = 10 AND dd = 31 THEN LOCATE week + 2, day: PRINT "Halloween"
  125.         IF m = 11 AND dd = 11 THEN LOCATE week + 2, day: PRINT "Veterans": LOCATE week + 3, day: PRINT "Day"
  126.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN LOCATE week + 2, day - 1: PRINT "Thanksgiving"
  127.         IF m = 12 AND dd = 25 THEN LOCATE week + 2, day + 1: PRINT "Christmas"
  128.         IF dd = days THEN GOTO more2:
  129.     NEXT day
  130.     w = 7
  131. NEXT week
  132. more2:
  133. a$ = INKEY$
  134. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  135. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  136. IF a$ = " " THEN GOTO start:
  137. GOTO more2:
  138.  
  139.  
  140. 'Find the right date for Easter.
  141. PAQUES:
  142. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  143. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  144. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  145. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  146. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  147. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  148.  
  149.  
  150. 'This section saves the calendar to a JPG file along with the SUB at the end of this program.
  151. saving:
  152. mo$ = STR$(m)
  153. mo$ = LTRIM$(RTRIM$(mo$))
  154. year$ = STR$(yy)
  155. year$ = LTRIM$(RTRIM$(year$))
  156. nm$ = mo$ + "-"
  157. nm$ = LTRIM$(RTRIM$(nm$))
  158. nm$ = nm$ + year$
  159. nm$ = LTRIM$(RTRIM$(nm$))
  160. SaveImage 0, nm$ 'saves entire program screen,"
  161. nm2$ = nm$ + ".jpg"
  162. nm2$ = LTRIM$(RTRIM$(nm2$))
  163. PRINT "          "; nm2$; " has been saved to your computer."
  164. INPUT "          Do you wish to make another calendar (Yes/No)"; ag$
  165. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  166. PRINT "          Goodbye."
  167.  
  168. weekdays:
  169.  
  170. 'This section gets the right weekday.
  171. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  172.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  173.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  174.     century = y MOD 100
  175.     zerocentury = y \ 100
  176.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  177.  
  178. 'This section saves the .jpg picture file.
  179. SUB SaveImage (image AS LONG, filename AS STRING)
  180.     bytesperpixel& = _PIXELSIZE(image&)
  181.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  182.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  183.     x& = _WIDTH(image&)
  184.     y& = _HEIGHT(image&)
  185.     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)
  186.     IF bytesperpixel& = 1 THEN
  187.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  188.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  189.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  190.         NEXT
  191.     END IF
  192.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  193.     lastsource& = _SOURCE
  194.     _SOURCE image&
  195.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  196.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  197.         r$ = ""
  198.         FOR px& = 0 TO x& - 1
  199.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  200.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  201.         NEXT px&
  202.         d$ = d$ + r$ + padder$
  203.     NEXT py&
  204.     _SOURCE lastsource&
  205.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  206.     b$ = b$ + d$ ' total file data bytes to create file
  207.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  208.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  209.     f& = FREEFILE
  210.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  211.     OPEN filename$ + ext$ FOR BINARY AS #f&
  212.     PUT #f&, , b$
  213.     CLOSE #f&
  214.  
  215.  
Title: Re: Calendar Maker
Post by: euklides on August 05, 2019, 04:13:05 am
Of course only available in the States for the holidays and national holidays.

Well done, and now the next steps would be :
- moon phase (%  %)
- spring, summer autumn & winter days...
- day number 1... 365 (356)
- week number 1... 52 (53)
- julian date

In fact, when you work with making a calendar, there are a lot of complications !
Title: Re: Calendar Maker
Post by: johnno56 on August 05, 2019, 10:14:39 am
Cool. Nicely done!
Title: Re: Calendar Maker
Post by: Jack002 on August 05, 2019, 10:31:24 am
Very cool. I once made a program that makes a calendar in HTML with tables. I was lazy and asked the user the number of days and what day the calendar starts on. I never put that in to automate that. This and mine would be an interesting combo.
[I have had a need for an html cal for years, its for a website I'm on]
Title: Re: Calendar Maker
Post by: SMcNeill on August 05, 2019, 10:48:02 am
Clippy’s “Calendos” Program from 1988.  I think it still works in QB64, but I haven’t tested it yet to be certain. 

Code: [Select]
CALENDOS.BAS
'
' COMPUTER GENERATED CALENDER
'
' FILE records all holidays and weekends
' for accurate business days in year
'
DEFINT A-Z
'_FULLSCREEN 'QB64
DECLARE SUB GetDay (strday$, daynm%)
DECLARE SUB LeapYear (yr%, Lpy$, fday%)
DECLARE SUB Easter (yrn%, EM%, ED%)
OPTION BASE 1
DIM Day%(7, 6)
DIM Hol%(4)
DIM Rel%(4)
CLS
10
CLS
SCREEN 13
OUT &H3C8, 0 'assign color number 1 TO 15 in Screen 12
OUT &H3C9, 0 'red value
OUT &H3C9, 0 'green value
OUT &H3C9, 15 'blue value

SOUND 300, 4
'SOUND 700, 3 'Opening screen
COLOR 9
LOCATE 5, 13: PRINT "CALENDOS PROGRAM"
LOCATE 20, 3: PRINT "Year number or enter for present year:"
in$ = ""
DO: _LIMIT 100 'Get Input from User QB64
a$ = INKEY$
IF a$ <> "" AND a$ > CHR$(47) AND a$ < CHR$(58) THEN 'filter for numbers only
in$ = in$ + a$
ELSEIF a$ <> "" THEN EXIT DO
END IF
LOCATE 10, 15: PRINT "Year = "; in$
LOOP UNTIL LEN(in$) = 4
SLEEP 1
IF LEN(in$) = 4 THEN
Year$ = in$ 'Get year from user 4 digit
ELSE: Year$ = MID$(DATE$, 7, 4) 'get year from the actual date
END IF

yrn% = VAL(Year$) ' Check for number of year for leap year calculate
yrnum% = yrn% 'yrnum% is for adding year in second January and display
LeapYear yrn%, Lpy$, frstday%
Easter yrn%, EM%, ED%


num% = frstday% ' set first month 1st day position for calendar
37
'_______________READ NUM OF DAYS _____________ INKEY LOOP for months
FOR month% = 1 TO 13 'includes January of next year 13 months
ERASE Day%
fst% = num% 'get first day number(day) from num% for other months

SELECT CASE month% 'DAYS OF MONTH
CASE 2
IF Lpy$ = "N" THEN days% = 28
IF Lpy$ = "Y" THEN days% = 29
CASE 4, 6, 9, 11
days% = 30
CASE ELSE ' all other months have 31 days
days% = 31
END SELECT
week% = 1
FOR d% = 1 TO days% 'ASSIGN NUMBERS TO DAYS ARRAY
Day%(num%, week%) = d%
IF num% = 7 THEN
num% = 0
week% = 1 + week%
END IF
num% = 1 + num% 'SET NUMBER FOR NEXT MONTH
NEXT d%

'>>>>>>>>>>>>>>>>>>>>>>>> SELECT HOLIDAYS

ERASE Hol%, Rel% 'for each month
mond% = 0
tue% = 0
thu% = 0
'ADJUST FOR MONTHS WITHOUT DAY IN 1ST WEEK
IF Day%(2, 1) = 0 THEN mond% = 1
IF Day%(5, 1) = 0 THEN thu% = 1
IF Day%(3, 1) = 0 THEN tue% = 1

SELECT CASE month% 'holiday 2nd monday = Day%(2, 3)
CASE 1
mon$ = "JANUARY"
Hol%(1) = 1
Hol%(2) = Day%(2, 3 + mond%)
CASE 2
mon$ = "FEBRUARY"
Hol%(1) = Day%(2, 3 + mond%)
CASE 3
mon$ = "MARCH"
IF EM% = 3 THEN Rel%(1) = ED%
CASE 4
mon$ = "APRIL"
IF EM% = 4 THEN Rel%(1) = ED%
CASE 5
mon$ = "MAY"
Hol%(1) = Day%(2, 4 + mond%)
IF Day%(2, 5 + mond%) > 0 THEN Hol%(1) = Day%(2, 5 + mond%) 'last monday of month
CASE 6
mon$ = "JUNE"
CASE 7
mon$ = "JULY"
Hol%(1) = 4
CASE 8
mon$ = "AUGUST"
CASE 9
mon$ = "SEPTEMBER"
Hol%(1) = Day%(2, 1 + mond%)
CASE 10
mon$ = "OCTOBER"
Hol%(1) = Day%(2, 2 + mond%)
CASE 11
mon$ = "NOVEMBER"
Hol%(1) = Day%(3, 1 + tue%)
Hol%(2) = 11
Hol%(3) = Day%(5, 4 + thu%)
CASE 12
mon$ = "DECEMBER"
Hol%(1) = 25
CASE 13
mon$ = "JANUARY"
Hol%(1) = 1
Hol%(2) = Day%(2, 3 + mond%)
END SELECT
tomonth$ = MID$(DATE$, 1, 2) 'Get todays month in time line
IF MID$(tomonth$, 1, 1) = "0" THEN tomonth$ = MID$(DATE$, 2, 1)
SELECT CASE tomonth$ 'get month name
CASE "1": moon$ = "Jan."
CASE "2": moon$ = "Feb."
CASE "3": moon$ = "Mar."
CASE "4": moon$ = "Apr."
CASE "5": moon$ = "May "
CASE "6": moon$ = "June"
CASE "7": moon$ = "July"
CASE "8": moon$ = "Aug."
CASE "9": moon$ = "Sep."
CASE "10": moon$ = "Oct."
CASE "11": moon$ = "Nov."
CASE "12": moon$ = "Dec."
END SELECT
today$ = MID$(DATE$, 4, 2) 'Get todays date
yr$ = MID$(DATE$, 7, 4)
'Figure name of the day of week near clock using actual date
IF month% = 1 THEN
datenum% = VAL(today$) 'find date number
monthnum% = VAL(tomonth$) 'find month number
yrno% = VAL(yr$) ' find year number
LeapYear yrno%, Lp$, fstday% 'check if leap Get first day position number
mon1st% = fstday%
FOR i% = 1 TO monthnum% - 1
SELECT CASE i%
CASE 2
IF Lp$ = "N" THEN mon1st% = mon1st% + 28 'Feb
IF Lp$ = "Y" THEN mon1st% = mon1st% + 29
CASE 4, 6, 9, 11
mon1st% = mon1st% + 30 'April, June, Sept, Nov
CASE ELSE
mon1st% = mon1st% + 31 ' all others have 31 days
END SELECT
NEXT i%
IF Lp$ = "N" THEN lpno% = 365
IF Lp$ = "Y" THEN lpno% = 366
dayofyear% = mon1st% + datenum% - fstday%
IF Lp$ = "Y" AND dayofyear% >= 60 THEN dayofyear% = dayofyear% + 1
fstofmo% = mon1st% MOD 7 'finds day value of 1st day of month
daynum% = (datenum% + fstofmo% - 1) MOD 7 'finds value of actual day

SELECT CASE daynum% 'assign week day name
CASE 0: wd$ = "Sat"
CASE 1: wd$ = "Sun"
CASE 2: wd$ = "Mon"
CASE 3: wd$ = "Tue"
CASE 4: wd$ = "Wed"
CASE 5: wd$ = "Thu"
CASE 6: wd$ = "Fri"
END SELECT
END IF
COLOR 8
CLS

'*********************** PRINT CALENDER
COLOR 8
LOCATE 23, 7: PRINT "Any key for next month! "
IF month% = 13 THEN
SOUND 500, 3
'SOUND 700, 4
yrnum% = yrnum% + 1 ' add 1 for next year
LOCATE 23, 7: PRINT " Any key ends program! "
END IF
COLOR 13
LOCATE 2, 8: PRINT mon$
LOCATE 2, 24: PRINT yrnum%
COLOR 1
LOCATE 4, 8: PRINT "S M T W T F S "
COLOR 7
LOCATE 21, 7: PRINT "Day Num"; dayofyear%; " Left"; lpno% - dayofyear%
'LOCATE and PRINT day numbers............. from Day%() Array
FOR r% = 1 TO 6 'week loop r% begin
FOR c% = 1 TO 7 'day loop and colors
COLOR 14 'normal day color
IF c% = 1 OR c% = 7 THEN COLOR 5 'color weekends
FOR i% = 1 TO 3
IF Day%(c%, r%) = Hol%(i%) THEN COLOR 4 ' color holidays
IF Day%(c%, r%) = Rel%(i%) THEN COLOR 3 ' color Easter day
NEXT i%
LOCATE (2 * r%) + 4, (3 * c%) + 4: PRINT Day%(c%, r%)
IF Day%(c%, r%) = 0 THEN LOCATE (2 * r%) + 4, (3 * c%) + 4: PRINT SPACE$(2)
NEXT c%
NEXT r% 'r% week loop end
'**********************BOX around Calendar
COLOR 6
'LOCATE 3, 6: PRINT STRING$(23, CHR$(223))
LINE (48, 16)-(225, 20), 6, BF 'TOP
'LOCATE 17, 6: PRINT STRING$(23, CHR$(220))
LINE (48, 130)-(225, 134), 6, BF 'BOTTOM
LINE (44, 16)-(48, 134), 6, BF 'left side
LINE (225, 16)-(229, 134), 6, BF 'right side
'FOR i% = 3 TO 17
'LOCATE i%, 6: PRINT STRING$(1, CHR$(176)) 'Sides
'LOCATE i%, 29: PRINT STRING$(1, CHR$(176))
' NEXT i%
'*******************************

LOCATE 18, 20: COLOR 4: PRINT "Holidays"
IF month% = EM% THEN COLOR 3: LOCATE 18, 8: PRINT "Easter"
COLOR 9
LOCATE 20, 7: PRINT wd$; ", "; moon$; datenum%

DO: _LIMIT 1 'continuous time loop NEXT MONTH LOOP INKEY
hour$ = LEFT$(TIME$, 2)
SELECT CASE hour$
CASE "00"
hr$ = "12"
CASE "01", "13"
hr$ = " 1"
CASE "02", "14"
hr$ = " 2"
CASE "03", "15"
hr$ = " 3"
CASE "04", "16"
hr$ = " 4"
CASE "05", "17"
hr$ = " 5"
CASE "06", "18"
hr$ = " 6"
CASE "07", "19"
hr$ = " 7"
CASE "08", "20"
hr$ = " 8"
CASE "09", "21"
hr$ = " 9"
CASE "10", "22"
hr$ = "10"
CASE "11", "23"
hr$ = "11"
CASE "12", "24"
hr$ = "12"
END SELECT
IF hour$ < "12" THEN aft$ = " AM" 'set AM PM
IF hour$ >= "12" THEN aft$ = " PM"
minu$ = MID$(TIME$, 3, 3)
sec$ = RIGHT$(TIME$, 3) 'minutes & seconds
COLOR 9
LOCATE 20, 20: PRINT hr$; minu$;
COLOR 2
COLOR 9
PRINT aft$
LOOP UNTIL INKEY$ <> ""
NEXT month%
60 CLOSE #1
100 CLS

LOCATE 4, 4: PRINT " CALENDOS "
LOCATE 7, 4: PRINT " Written by Ted Weissgerber"
LOCATE 10, 4: PRINT " burger2227@Gmail.com"
LOCATE 14, 4: PRINT " 2010"
LOCATE 18, 4: PRINT " Qbasic and DOS Rule!"

SLEEP 3
SYSTEM

SUB Easter (yrn, EM, ED)
c = yrn \ 100 'Century
G = yrn MOD 19
K = (c - 17) \ 25
i = (c - (c \ 4) - (c - K) \ 3 + (19 * G) + 15) MOD 30
i = i - (i \ 28) * (1 - (i \ 28) * (29 \ (i + 1)) * ((21 - G) \ 11))
J = (yrn + yrn \ 4 + i + 2 - c + c \ 4) MOD 7
L = i - J
EM = 3 + (L + 40) \ 44 'Month of Easter.
ED = L + 28 - 31 * (EM \ 4) 'Day of Easter.
END SUB

SUB LeapYear (yrn%, Leap$, firstday%)
'my LEAP YEAR and the First Day of Year routine based on year 2000
LpYear% = 2000
firstday% = 7 ' the first day of 2000 was a saturday, the 7th day
IF yrn% >= 2000 THEN ' ** yrn% INPUT
'FORWARD LOOP 2000 up
yrnm% = 1999 'start in 1999
DO
yrnm% = yrnm% + 1 ' start in 2000 (1999 + 1)
IF yrnm% > 2000 THEN firstday% = firstday% + 1 'add one day every year to first day (52 weeks + 1
IF firstday% > 7 THEN firstday% = firstday% - 7 ' ** firstday% OUTPUT

IF yrnm% = LpYear% THEN Leap$ = "Y" ' ** Lp$ for print only
IF yrnm% MOD 100 = 0 THEN nly% = LpYear% MOD 400 'test century leap 400
IF nly% <> 0 THEN Leap$ = "N" ' if not divisible by 400

IF yrnm% - 1 = LpYear% THEN ' add day AFTER leap year
IF nly% = 0 THEN firstday% = firstday% + 1 ' add a leap day
IF firstday% > 7 THEN firstday% = firstday% - 7
Leap$ = "N"
LpYear% = LpYear% + 4 ' find next leap year by adding 4
END IF
nly% = 0 ' reset MOD value
LOOP UNTIL yrnm% = yrn%
END IF 'end forward loop

IF yrn% < 2000 THEN 'REVERSE LOOP 2000 down
yrnm% = 2001 'start in 2001
DO
yrnm% = yrnm% - 1 ' start in 2000 (2001 - 1)
IF yrnm% < 2000 THEN firstday% = firstday% - 1 'subt one day every year to first day (52 weeks + 1
IF firstday% = 0 THEN firstday% = 7
IF yrnm% MOD 100 = 0 THEN nly% = LpYear% MOD 400 ' test century every 100
Leap$ = "N"

IF yrnm% = LpYear% THEN ' BEFORE leap year
IF nly% = 0 AND LpYear% <> 2000 THEN firstday% = firstday% - 1 ' subt a leap day
IF firstday% = 0 THEN firstday% = 7
LpYear% = LpYear% - 4 ' find next leap year
Leap$ = "Y"
IF nly% <> 0 THEN Leap$ = "N" ' if not divisible by 400
END IF
nly% = 0 ' reset MOD value
LOOP UNTIL yrnm% = yrn%
END IF
END SUB
Title: Re: Calendar Maker
Post by: bplus on August 05, 2019, 12:08:04 pm
Wow SAM never saw OUT before, watch OUT!

Looks like Ted Weissgerber code good for thumbnail sketches on screen, has complex Leap Year Calc and another Easter Calc.
Title: Re: Calendar Maker
Post by: SierraKen on August 05, 2019, 12:20:12 pm
LOL that's a cute little program. But it's not from 1988, it has a gmail address in the code and it mentions QBasic with the year 2010.

Title: Re: Calendar Maker
Post by: SMcNeill on August 05, 2019, 12:23:57 pm
LOL that's a cute little program. But it's not from 1988, it has a gmail address in the code and it mentions QBasic with the year 2010.

It’s from 88, but has been translated a few times over the years.  Clippy even has an Android version of it, somewhere, where it was translated to run on it.  ;)

(Here’s a link to where he was talking about it back in 2008, over at the QBASIC forums: https://www.tapatalk.com/groups/qbasic/how-calculate-week-number-t29545-s20.html)

The QBASIC forums go back 30 years, or so, but a lot of the older stuff is archived for historical preservation and disk storage, so it’s not exactly search friendly.  2008 is the oldest non-archived post I can find on his Calendos program, but he mentions it originated back in 88, and I have no real reason to doubt it.  ;)
Title: Re: Calendar Maker
Post by: SierraKen on August 05, 2019, 07:56:18 pm
Well, I am (hopefully) minutes away from making this a GREAT calendar program. But I need help from you guys badly.  It could be minutes from being completed, but the problem I ran into is that the program freezes after you print it out using the program (Yes, I added printing to it!). It saves and prints the first one fine. But then it asks you if you want to make another calendar, so it goes back to the first screen to do that and after you add both the year and month, it just sits there... does nothing... And I have no idea why. I've looked through the code and I'm tried testing it in a few places, etc. but can't figure it out. Have you guys ran into problems before where a printer freezes a program? If we can't fix this, I'll just remove the part where it asks if you want to make a new calendar after printing, and just make the program end. I added a lot to it. In order to make it print good calendars, I got code from the Wiki pages where an example shows how to flip a picture certain degrees, it originally says 360 degrees but I changed it to 90 so it would fit good on paper. If you have a printer, please try it out. You can watch the calendar being turned 90 degrees, is really cool. Anyway, any help is appreciated, and I want to thank B+ for telling me about PRINTSTRING, which I also changed to so now the numbers line up perfectly and the holidays fit a lot better. Tell me what you think, thanks. Remember, it makes them, saves them, and prints them fine the first time, but you can't even make one the second time. Oh, I also tried _FREEIMAGE on p& which is the screen the printer prints, but it won't let me do that for some reason, but it will let me do _FREEIMAGE on the picture itself. Could that be a problem? Having a SCREEN _NEWIMAGE(800, 900), p&  overlapping the _SOURCE img& ? It's lines between 205 and 235. It might not be the problem though because it lets you go back to the front screen though to setup a new calendar. Although, could there be a conflict when you press enter and it makes another SCREEN _NEWIMAGE(800,600,32) for the new calendar? Also notice that the printer image doesn't use the last 32 number because it prints black all around the calendar, which looks neat but is too costly for toner. I wonder if that's a conflict though? Sorry for so many questions, this program just means a lot to me.

(Note: This version has an error in it, so please keep scrolling to my next one, thanks.)

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

I modified a small portion of your code to print calendar displayed directly without need to save image:
Code: QB64: [Select]
  1. more2:
  2. _LIMIT 1000
  3. a$ = INKEY$
  4. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  5. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  6. IF a$ = " " THEN GOTO start:
  7. IF a$ = "p" OR a$ = "P" THEN
  8.     'see title change  copy here:
  9.     _TITLE "Press 'S' to Save, 'P' to Print (can do again for copy) , Space Bar to make another calendar, or 'Esc' to quit."
  10.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  11.     YMAX = _HEIGHT: XMAX = _WIDTH
  12.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  13.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  14.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  15.     _PRINTIMAGE landscape& '<<<<<<<<<<<<<<<<<<<<<<<<< debug first before wasting paper and ink
  16. GOTO more2:
  17.  

You can press p for as many copies as you want then press space to go back and do another month.
Title: Re: Calendar Maker
Post by: bplus on August 05, 2019, 10:36:11 pm
Code: QB64: [Select]
  1. printing:
  2. SCREEN _NEWIMAGE(800, 900), p&
  3.  

I don't understand this line (with _NEWIMAGE). Nothing in Wiki Syntax line says anything about parameters after the ), but there is an example that shows a setup for page flipping that uses parameters after the ).

So Wiki needs a fix?
Title: Re: Calendar Maker
Post by: SMcNeill on August 05, 2019, 10:49:39 pm
Code: QB64: [Select]
  1. printing:
  2. SCREEN _NEWIMAGE(800, 900), p&
  3.  

I don't understand this line (with _NEWIMAGE). Nothing in Wiki Syntax line says anything about parameters after the ), but there is an example that shows a setup for page flipping that uses parameters after the ).

So Wiki needs a fix?

Nope.  It’s part of the SCREEN syntax.

SCREEN imagehandle& [, , active_page, visual_page]

Though I’m not exactly certain what the ,p& parameter represents.


https://www.qbasic.net/en/reference/qb11/Statement/SCREEN.htm

Color setting?

Doesn’t look like QB64 supports that parameter, which is why it lists the command as: SCREEN {mode%|imagehandle&} , , active_page, visual_page]

(See the comma comma with nothing between it?
Title: Re: Calendar Maker
Post by: SierraKen on August 05, 2019, 10:58:37 pm
Back when I made my Paint Pixels program, I took that has a variable that stores the entire screen to it so you can use it later. But I could be wrong.
Title: Re: Calendar Maker
Post by: SierraKen on August 05, 2019, 11:07:07 pm
Well, thanks to B+ I did it!!!!! I deleted the old printing code and used B+'s instead and it works great! Thank you and also to Euklides and SmMcNeill for the help in making this. On the start page, under "By Ken G." I added "With some help from the QB64.org forum guys!". Maybe it will attract programmers here sometime.
Now I got a fully-working Calendar Maker that makes any month from the mid 1700's to 9999. It labels some of the holidays, can save it as a .jpg file to your computer, and can print it to the printer!     I'll put this on my website very soon, which is http://www.KensPrograms.com/
Save this program to its own directory so you can find all of your saved calendars easily. I hope some of you enjoy this and use it sometimes.

(Note: On the next page of this forum topic, I posted an even better version adding some more holidays and also the ability to use arrow keys to change months.)

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 Monday, August 5, 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 make a new calendar without saving, press the Space Bar."
  36. PRINT "             Keyboard commands will be listed on the title bar of the window."
  37. again1:
  38. INPUT "             Type the year here (1753-9999): ", y
  39. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again1:
  40. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  41. again2:
  42. INPUT "             Type the month here (1-12): ", m
  43. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  44. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  45.  
  46. 'Get the month name.
  47. IF m = 1 THEN month$ = " January"
  48. IF m = 2 THEN month$ = "February"
  49. IF m = 3 THEN month$ = "  March"
  50. IF m = 4 THEN month$ = "  April"
  51. IF m = 5 THEN month$ = "  May"
  52. IF m = 6 THEN month$ = "  June"
  53. IF m = 7 THEN month$ = "  July"
  54. IF m = 8 THEN month$ = " August"
  55. IF m = 9 THEN month$ = "September"
  56. IF m = 10 THEN month$ = " October"
  57. IF m = 11 THEN month$ = "November"
  58. IF m = 12 THEN month$ = "December"
  59.  
  60. 'Calculate to see if it's a Leap Year.
  61. IF m <> 2 THEN GOTO nex:
  62. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  63. IF y / 4 = INT(y / 4) THEN leap = 1
  64. IF y / 100 = INT(y / 100) THEN leap = 0
  65.  
  66. 'Get the number of days for each month.
  67. more:
  68. IF leap = 1 THEN days = 29
  69. IF leap = 0 THEN days = 28
  70. GOTO weekday:
  71. nex:
  72. IF m = 1 THEN days = 31
  73. IF m = 3 THEN days = 31
  74. IF m = 4 THEN days = 30
  75. IF m = 5 THEN days = 31
  76. IF m = 6 THEN days = 30
  77. IF m = 7 THEN days = 31
  78. IF m = 8 THEN days = 31
  79. IF m = 9 THEN days = 30
  80. IF m = 10 THEN days = 31
  81. IF m = 11 THEN days = 30
  82. IF m = 12 THEN days = 31
  83. weekday:
  84.  
  85. 'Set the month, year, and weekday variables to start with.
  86. mm = m
  87. yy = y
  88. GetDay mm, dd, y, weekday
  89.  
  90. 'This section makes the calendar graph.
  91. make:
  92. SCREEN _NEWIMAGE(800, 600, 32)
  93. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  94. _TITLE "Press 'S' to Save, 'P' to Print (can do again for copy), Space Bar to make another calendar, or 'Esc' to quit."
  95. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  96. LOCATE 3, 42: PRINT month$; "  "; yy
  97.  
  98. FOR x = 20 TO 780 STEP 108
  99.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  100. FOR z = 100 TO 580 STEP 80
  101.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  102.  
  103. LOCATE 5, 8: PRINT "SUNDAY"
  104. LOCATE 5, 21: PRINT "MONDAY"
  105. LOCATE 5, 34: PRINT "TUESDAY"
  106. LOCATE 5, 47: PRINT "WEDNESDAY"
  107. LOCATE 5, 60: PRINT "THURSDAY"
  108. LOCATE 5, 75: PRINT "FRIDAY"
  109. LOCATE 5, 87: PRINT "SATURDAY"
  110.  
  111. 'Finding Date of Easter
  112. PQA = yy
  113. GOSUB PAQUES
  114. 'month = PQM, day = PQJ, year = PQA
  115.  
  116. 'This section puts the right dates and holidays in the right squares for the calendar.
  117. w = (weekday * 108) + 25
  118. FOR weeky = 110 TO 570 STEP 80
  119.     FOR dayx = w TO 692 STEP 108
  120.         _LIMIT 1000
  121.         dd = dd + 1
  122.         GetDay mm, dd, y, weekday
  123.         dd$ = STR$(dd)
  124.         _FONT 16
  125.         _PRINTSTRING (dayx, weeky), dd$
  126.         _FONT 8
  127.         IF m = 1 AND dd = 1 THEN _PRINTSTRING (dayx + 10, weeky + 60), "New Years":
  128.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  129.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  130.         IF m = 2 AND dd = 14 THEN _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  131.         IF m = PQM AND dd = PQJ THEN _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  132.         IF m = 5 AND weekday = 2 AND dd > 24 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  133.         IF m = 7 AND dd = 4 THEN _PRINTSTRING (dayx, weeky + 60), "Independence"
  134.         IF m = 9 AND weekday = 2 AND dd < 8 THEN _PRINTSTRING (dayx + 25, weeky + 60), "Labor"
  135.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Columbus"
  136.         IF m = 10 AND dd = 31 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  137.         IF m = 11 AND dd = 11 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Veterans"
  138.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN _PRINTSTRING (dayx, weeky + 60), "Thanksgiving"
  139.         IF m = 12 AND dd = 25 THEN _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  140.  
  141.         IF dd = days THEN _FONT 16: GOTO more2:
  142.     NEXT dayx
  143.     w = 25
  144. NEXT weeky
  145.  
  146. more2:
  147. _LIMIT 1000
  148. a$ = INKEY$
  149. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  150. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  151. IF a$ = " " THEN GOTO start:
  152. IF a$ = "p" OR a$ = "P" THEN
  153.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  154.     YMAX = _HEIGHT: XMAX = _WIDTH
  155.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  156.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  157.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  158.     _PRINTIMAGE landscape&
  159.  
  160. GOTO more2:
  161.  
  162.  
  163. 'Find the right date for Easter.
  164. PAQUES:
  165. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  166. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  167. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  168. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  169. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  170. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  171.  
  172.  
  173. 'This section saves the calendar to a JPG file along with the SUB at the end of this program.
  174. saving:
  175. mo$ = STR$(m)
  176. mo$ = LTRIM$(RTRIM$(mo$))
  177. year$ = STR$(yy)
  178. year$ = LTRIM$(RTRIM$(year$))
  179. nm$ = mo$ + "-"
  180. nm$ = LTRIM$(RTRIM$(nm$))
  181. nm$ = nm$ + year$
  182. nm$ = LTRIM$(RTRIM$(nm$))
  183. SaveImage 0, nm$ 'saves entire program screen,"
  184. nm2$ = nm$ + ".jpg"
  185. nm2$ = LTRIM$(RTRIM$(nm2$))
  186. PRINT "                                           Saving"
  187. PRINT "                          "; nm2$; " has been saved to your computer."
  188. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  189. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  190. PRINT "                         Goodbye."
  191.  
  192. weekdays:
  193.  
  194. 'This section gets the right weekday.
  195. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  196.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  197.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  198.     century = y MOD 100
  199.     zerocentury = y \ 100
  200.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  201.  
  202. 'This section saves the .jpg picture file.
  203. SUB SaveImage (image AS LONG, filename AS STRING)
  204.     bytesperpixel& = _PIXELSIZE(image&)
  205.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  206.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  207.     x& = _WIDTH(image&)
  208.     y& = _HEIGHT(image&)
  209.     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)
  210.     IF bytesperpixel& = 1 THEN
  211.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  212.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  213.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  214.         NEXT
  215.     END IF
  216.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  217.     lastsource& = _SOURCE
  218.     _SOURCE image&
  219.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  220.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  221.         r$ = ""
  222.         FOR px& = 0 TO x& - 1
  223.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  224.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  225.         NEXT px&
  226.         d$ = d$ + r$ + padder$
  227.     NEXT py&
  228.     _SOURCE lastsource&
  229.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  230.     b$ = b$ + d$ ' total file data bytes to create file
  231.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  232.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  233.     f& = FREEFILE
  234.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  235.     OPEN filename$ + ext$ FOR BINARY AS #f&
  236.     PUT #f&, , b$
  237.     CLOSE #f&
  238.  
  239.  
Title: Re: Calendar Maker
Post by: bplus on August 05, 2019, 11:34:05 pm
Nope.  It’s part of the SCREEN syntax.

SCREEN imagehandle& [, , active_page, visual_page]

Though I’m not exactly certain what the ,p& parameter represents.


https://www.qbasic.net/en/reference/qb11/Statement/SCREEN.htm

Color setting?

Doesn’t look like QB64 supports that parameter, which is why it lists the command as: SCREEN {mode%|imagehandle&} , , active_page, visual_page]

(See the comma comma with nothing between it?

Aha! now I get it, it's a part of SCREEN sub call, actually that line I have always been using makes more sense to me now. Thanks Steve.


Hi, Ken,

I thought you might like that change. :)
Title: Re: Calendar Maker
Post by: SierraKen 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.  
Title: Re: Calendar Maker
Post by: bplus on August 06, 2019, 05:00:31 pm
Nice simple improvement!
Title: Re: Calendar Maker
Post by: SierraKen 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
Title: Re: Calendar Maker
Post by: johnno56 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
Title: Re: Calendar Maker
Post by: SierraKen 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
Title: Re: Calendar Maker
Post by: PauloC on August 07, 2019, 01:56:28 pm
This program is very useful to learn QB64. Thank you!
Title: Re: Calendar Maker
Post by: SierraKen on August 07, 2019, 04:04:10 pm
Welcome PauloC!
Title: Re: Calendar Maker
Post by: pforpond 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 :)
Title: Re: Calendar Maker
Post by: SierraKen 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.
Title: Re: Calendar Maker
Post by: TempodiBasic on August 11, 2019, 06:23:05 pm
Hi
Good Application!
IMHO next step is to colorize holydays and sunday
Title: Re: Calendar Maker
Post by: SierraKen on August 11, 2019, 08:42:45 pm
Thanks TempodiBasic.
Title: Re: Calendar Maker
Post by: SierraKen 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.  




Title: Re: Calendar Maker
Post by: bplus 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 :)
Title: Re: Calendar Maker
Post by: SierraKen 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. 
Title: Re: Calendar Maker
Post by: bplus 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.
Title: Re: Calendar Maker
Post by: OldMoses on September 15, 2019, 12:15:57 pm
Great program, this will be useful. I've officially awarded you a subdirectory in my 'programs' folder. ;)
Title: Re: Calendar Maker
Post by: SierraKen on September 15, 2019, 07:39:53 pm
Wow thanks OldMoses! :)
Title: Re: Calendar Maker
Post by: TempodiBasic on September 17, 2019, 06:42:07 pm
Fine again...

Thanks to share and thanks to improve

but

1) no Sunday color and not holiday color
3) no customizable names of months and of days... it can be done using a keyboard / file input
2) it is just right for American recurrences...and it is ok... but a great improvement should be to become customizable by user just by clicking on the day to activate as Holiday or to take input the list of holidays or recurrences at the beginning of the choice of the year or from a file ...

Title: Re: Calendar Maker
Post by: SierraKen on September 18, 2019, 06:47:02 pm
Sunday or Holidays color change are possible. But removing or adding holidays might be impossible because holidays don't just come the same day every year. Many U.S. holidays happen on certain weekdays of certain months and the dates of them are changed every year. But I'll look into the Sunday and holidays changes, thanks. I doubt I will add a data file to this program because personally, I have no need for one. I thought about making it a calendar to put any info you want on any day of the year, but I use a paper day-to-day calendar myself and I wouldn't want people to rely on a computer program for important appointments they need to go to, especially medical appointments. Although Windows already has something like this built-in anyway. But thanks for the suggestions, I'll look into some color changes a little bit I think, when I have time.
Title: Re: Calendar Maker
Post by: SierraKen on September 18, 2019, 08:06:16 pm
OK I got the Sundays and holidays colored yellow. :) Thanks again Tempodi for the idea! They look awesome this way. I can't test the colors with my printer though because I have a b/w printer but I'm guessing it does print yellow just like everything else. I will print out a b/w version of it soon. But on the computer I really like it.
Oh, and I won't let people change colors for the entire calendar because it takes up too much ink or toner.
Here is the updated version:

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

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 colored Sundays and holidays.
  6. 'Made on Wednesday, September 18, 2019 by Ken G.
  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.         IF weekday = 1 THEN GOSUB coloring:
  126.         IF weekday <> 1 THEN COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  127.         dd$ = STR$(dd)
  128.         _FONT 8
  129.         IF m = 1 AND dd = 1 THEN
  130.             GOSUB coloring:
  131.             _PRINTSTRING (dayx + 15, weeky + 60), "New Years"
  132.         END IF
  133.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  134.             GOSUB coloring:
  135.             _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  136.         END IF
  137.         IF m = 2 AND dd = 2 THEN
  138.             GOSUB coloring:
  139.             _PRINTSTRING (dayx + 13, weeky + 60), "Groundhog"
  140.         END IF
  141.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  142.             GOSUB coloring:
  143.             _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  144.         END IF
  145.         IF m = 2 AND dd = 14 THEN
  146.             GOSUB coloring:
  147.             _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  148.         END IF
  149.         IF m = 3 AND dd = 17 THEN
  150.             GOSUB coloring:
  151.             _PRINTSTRING (dayx + 5, weeky + 60), "St. Patrick"
  152.         END IF
  153.         IF m = PQM AND dd = PQJ THEN
  154.             GOSUB coloring:
  155.             _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  156.         END IF
  157.         IF m = 4 AND dd > 23 AND weekday = 7 THEN
  158.             GOSUB coloring:
  159.             _PRINTSTRING (dayx + 25, weeky + 60), "Arbor"
  160.         END IF
  161.         IF m = 5 AND weekday = 0 AND dd > 14 AND dd < 22 THEN
  162.             GOSUB coloring:
  163.             _PRINTSTRING (dayx + 2, weeky + 60), "Armed Forces"
  164.         END IF
  165.         IF m = 5 AND weekday = 2 AND dd > 24 THEN
  166.             GOSUB coloring:
  167.             _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  168.         END IF
  169.         IF m = 5 AND weekday = 1 AND dd > 7 AND dd < 15 THEN
  170.             GOSUB coloring:
  171.             _PRINTSTRING (dayx + 2, weeky + 60), "Mother's Day"
  172.         END IF
  173.         IF m = 6 AND weekday = 1 AND dd > 14 AND dd < 22 THEN
  174.             GOSUB coloring:
  175.             _PRINTSTRING (dayx + 2, weeky + 60), "Father's Day"
  176.         END IF
  177.         IF m = 6 AND dd = 14 THEN
  178.             GOSUB coloring:
  179.             _PRINTSTRING (dayx + 35, weeky + 60), "Flag"
  180.         END IF
  181.         IF m = 7 AND dd = 4 THEN
  182.             GOSUB coloring:
  183.             _PRINTSTRING (dayx + 2, weeky + 60), "Independence"
  184.         END IF
  185.         IF m = 9 AND weekday = 2 AND dd < 8 THEN
  186.             GOSUB coloring:
  187.             _PRINTSTRING (dayx + 27, weeky + 60), "Labor"
  188.         END IF
  189.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN
  190.             GOSUB coloring:
  191.             _PRINTSTRING (dayx + 17, weeky + 60), "Columbus"
  192.         END IF
  193.         IF m = 10 AND dd = 31 THEN
  194.             GOSUB coloring:
  195.             _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  196.         END IF
  197.         IF m = 11 AND dd = 11 THEN
  198.             GOSUB coloring:
  199.             _PRINTSTRING (dayx + 19, weeky + 60), "Veterans"
  200.         END IF
  201.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN
  202.             GOSUB coloring:
  203.             _PRINTSTRING (dayx + 2, weeky + 60), "Thanksgiving"
  204.         END IF
  205.         IF m = 12 AND dd = 25 THEN
  206.             GOSUB coloring:
  207.             _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  208.         END IF
  209.         _FONT 16
  210.         _PRINTSTRING (dayx, weeky), dd$
  211.         _FONT 8
  212.         IF dd = days THEN _FONT 16: GOTO more2:
  213.     NEXT dayx
  214.     w = 25
  215. NEXT weeky
  216.  
  217. more2:
  218. _LIMIT 1000
  219. a$ = INKEY$
  220. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  221. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  222. IF a$ = " " THEN GOTO start:
  223. IF a$ = "p" OR a$ = "P" THEN
  224.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  225.     YMAX = _HEIGHT: XMAX = _WIDTH
  226.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  227.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  228.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  229.     _PRINTIMAGE landscape&
  230.  
  231. IF a$ = CHR$(0) + CHR$(77) THEN
  232.     m = m + 1
  233.     IF m > 12 THEN
  234.         m = 1
  235.         yy = yy + 1
  236.     END IF
  237.     y = yy
  238.     IF y > 9999 THEN y = 1753
  239.     dd = 0
  240.     leap = 0
  241.     _DELAY .1
  242.     CLS
  243.     GOTO calculate:
  244. IF a$ = CHR$(0) + CHR$(75) THEN
  245.     m = m - 1
  246.     IF m < 1 THEN
  247.         m = 12
  248.         yy = yy - 1
  249.     END IF
  250.     y = yy
  251.     IF y < 1753 THEN y = 9999
  252.     dd = 0
  253.     leap = 0
  254.     _DELAY .1
  255.     CLS
  256.     GOTO calculate:
  257.  
  258. GOTO more2:
  259.  
  260. 'Color all Sundays and holidays
  261. coloring:
  262. LINE (dayx - 4, weeky - 9)-(dayx + 102, weeky + 68), _RGB32(255, 255, 127), BF: COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 127)
  263.  
  264.  
  265. 'Find the right date for Easter.
  266. PAQUES:
  267. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  268. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  269. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  270. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  271. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  272. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  273.  
  274.  
  275. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  276. saving:
  277. mo$ = STR$(m)
  278. mo$ = LTRIM$(RTRIM$(mo$))
  279. year$ = STR$(yy)
  280. year$ = LTRIM$(RTRIM$(year$))
  281. nm$ = mo$ + "-"
  282. nm$ = LTRIM$(RTRIM$(nm$))
  283. nm$ = nm$ + year$
  284. nm$ = LTRIM$(RTRIM$(nm$))
  285. SaveImage 0, nm$ 'saves entire program screen,"
  286. nm2$ = nm$ + ".bmp"
  287. nm2$ = LTRIM$(RTRIM$(nm2$))
  288. PRINT "                                           Saving"
  289. PRINT "                          "; nm2$; " has been saved to your computer."
  290. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  291. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  292. PRINT "                         Goodbye."
  293.  
  294. weekdays:
  295.  
  296. 'This section gets the right weekday.
  297. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  298.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  299.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  300.     century = y MOD 100
  301.     zerocentury = y \ 100
  302.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  303.  
  304. 'This section saves the .bmp picture file.
  305. SUB SaveImage (image AS LONG, filename AS STRING)
  306.     bytesperpixel& = _PIXELSIZE(image&)
  307.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  308.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  309.     x& = _WIDTH(image&)
  310.     y& = _HEIGHT(image&)
  311.     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)
  312.     IF bytesperpixel& = 1 THEN
  313.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  314.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  315.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  316.         NEXT
  317.     END IF
  318.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  319.     lastsource& = _SOURCE
  320.     _SOURCE image&
  321.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  322.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  323.         r$ = ""
  324.         FOR px& = 0 TO x& - 1
  325.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  326.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  327.         NEXT px&
  328.         d$ = d$ + r$ + padder$
  329.     NEXT py&
  330.     _SOURCE lastsource&
  331.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  332.     b$ = b$ + d$ ' total file data bytes to create file
  333.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  334.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  335.     f& = FREEFILE
  336.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  337.     OPEN filename$ + ext$ FOR BINARY AS #f&
  338.     PUT #f&, , b$
  339.     CLOSE #f&
  340.  
  341.  
Title: Re: Calendar Maker
Post by: SierraKen on September 19, 2019, 02:12:35 pm
I just added the option of creating a calendar without holidays so people of other countries can write-in ones of their own after they print them on paper. It still has all the Sundays as yellow.

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 colored Sundays and holidays and the option of not having U.S. holidays.
  6. 'Made on Thursday, September 19, 2019 by Ken G.
  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. holidays = 0
  21. SCREEN _NEWIMAGE(800, 600, 32)
  22. PRINT "                                  Monthly Calendar Maker"
  23. PRINT "                                        By Ken G."
  24. PRINT "                         With some help from the QB64.org Forum guys!"
  25. PRINT "          This program will make a calendar for the year and month you want."
  26. PRINT "          It will also name some U.S. holidays on their dates if you choose that."
  27. PRINT "          This uses the Gregorian Calendar which became common practice in"
  28. PRINT "          England in 1753 and we still use it today."
  29. PRINT "          First make a calendar, then if you want to save it as a .bmp file,"
  30. PRINT "          press the 'S' key and it will save it as the month and year for its name."
  31. PRINT "          For example, if you made a calendar for January 2020 and wish to save it,"
  32. PRINT "          press the 'S' key and it will save it as 1-2020.bmp"
  33. PRINT "          If you wish to print your calendar on your printer, press 'P' once."
  34. PRINT "          Feel free to print as many times as you wish. They take up 1 page each."
  35. PRINT "          If you save the .bmp calendar, it will be put in the same directory as this program."
  36. PRINT "          To switch to the last month use the left arrow key, to the next month the right arrow key."
  37. PRINT "          To make a different calendar without saving, press the Space Bar."
  38. PRINT "          Keyboard commands will be listed on the title bar of the window."
  39. again1:
  40. INPUT "          Type the year here (1753-9999): ", y
  41. IF y <> INT(y) THEN PRINT "Cannot use decimals, try again.": GOTO again1:
  42. IF y < 1753 OR y > 9999 THEN PRINT "The year can only be between 1753 and 9999, try again.": GOTO again1:
  43. again2:
  44. INPUT "          Type the month here (1-12): ", m
  45. IF m <> INT(m) THEN PRINT "Cannot use decimals, try again.": GOTO again2:
  46. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  47. INPUT "          Do you want U.S. holidays added (Y/N)?", hol$
  48. IF LEFT$(hol$, 1) = "y" OR LEFT$(hol$, 1) = "Y" THEN holidays = 1
  49. calculate:
  50. 'Get the month name.
  51. IF m = 1 THEN month$ = " January"
  52. IF m = 2 THEN month$ = "February"
  53. IF m = 3 THEN month$ = "  March"
  54. IF m = 4 THEN month$ = "  April"
  55. IF m = 5 THEN month$ = "  May"
  56. IF m = 6 THEN month$ = "  June"
  57. IF m = 7 THEN month$ = "  July"
  58. IF m = 8 THEN month$ = " August"
  59. IF m = 9 THEN month$ = "September"
  60. IF m = 10 THEN month$ = " October"
  61. IF m = 11 THEN month$ = "November"
  62. IF m = 12 THEN month$ = "December"
  63.  
  64. 'Calculate to see if it's a Leap Year.
  65. IF m <> 2 THEN GOTO nex:
  66. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  67. IF y / 4 = INT(y / 4) THEN leap = 1
  68. IF y / 100 = INT(y / 100) THEN leap = 0
  69.  
  70. 'Get the number of days for each month.
  71. more:
  72. IF leap = 1 THEN days = 29
  73. IF leap = 0 THEN days = 28
  74. GOTO weekday:
  75. nex:
  76. IF m = 1 THEN days = 31
  77. IF m = 3 THEN days = 31
  78. IF m = 4 THEN days = 30
  79. IF m = 5 THEN days = 31
  80. IF m = 6 THEN days = 30
  81. IF m = 7 THEN days = 31
  82. IF m = 8 THEN days = 31
  83. IF m = 9 THEN days = 30
  84. IF m = 10 THEN days = 31
  85. IF m = 11 THEN days = 30
  86. IF m = 12 THEN days = 31
  87. weekday:
  88.  
  89. 'Set the month, year, and weekday variables to start with.
  90. mm = m
  91. yy = y
  92. GetDay mm, dd, y, weekday
  93.  
  94. 'This section makes the calendar graph.
  95. make:
  96. SCREEN _NEWIMAGE(800, 600, 32)
  97. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  98. _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."
  99. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  100. LOCATE 3, 42: PRINT month$; "  "; yy
  101.  
  102. FOR x = 20 TO 780 STEP 108
  103.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  104. FOR z = 100 TO 580 STEP 80
  105.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  106.  
  107. LOCATE 5, 8: PRINT "SUNDAY"
  108. LOCATE 5, 21: PRINT "MONDAY"
  109. LOCATE 5, 34: PRINT "TUESDAY"
  110. LOCATE 5, 47: PRINT "WEDNESDAY"
  111. LOCATE 5, 60: PRINT "THURSDAY"
  112. LOCATE 5, 75: PRINT "FRIDAY"
  113. LOCATE 5, 87: PRINT "SATURDAY"
  114.  
  115. 'Finding Date of Easter
  116. PQA = yy
  117. GOSUB PAQUES
  118. 'month = PQM, day = PQJ, year = PQA
  119.  
  120. 'This section puts the right dates and holidays in the right squares for the calendar.
  121. w = (weekday * 108) + 25
  122. FOR weeky = 110 TO 570 STEP 80
  123.     FOR dayx = w TO 692 STEP 108
  124.         _LIMIT 1000
  125.         dd = dd + 1
  126.         GetDay mm, dd, y, weekday
  127.         IF weekday = 1 THEN GOSUB coloring:
  128.         IF weekday <> 1 THEN COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  129.         dd$ = STR$(dd)
  130.         IF holidays = 0 THEN GOTO skip:
  131.         _FONT 8
  132.         IF m = 1 AND dd = 1 THEN
  133.             GOSUB coloring:
  134.             _PRINTSTRING (dayx + 15, weeky + 60), "New Years"
  135.         END IF
  136.         IF m = 1 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  137.             GOSUB coloring:
  138.             _PRINTSTRING (dayx + 25, weeky + 60), "MLK Jr."
  139.         END IF
  140.         IF m = 2 AND dd = 2 THEN
  141.             GOSUB coloring:
  142.             _PRINTSTRING (dayx + 13, weeky + 60), "Groundhog"
  143.         END IF
  144.         IF m = 2 AND weekday = 2 AND dd > 14 AND dd < 22 THEN
  145.             GOSUB coloring:
  146.             _PRINTSTRING (dayx + 10, weeky + 60), "Presidents"
  147.         END IF
  148.         IF m = 2 AND dd = 14 THEN
  149.             GOSUB coloring:
  150.             _PRINTSTRING (dayx + 10, weeky + 60), "Valentines"
  151.         END IF
  152.         IF m = 3 AND dd = 17 THEN
  153.             GOSUB coloring:
  154.             _PRINTSTRING (dayx + 5, weeky + 60), "St. Patrick"
  155.         END IF
  156.         IF m = PQM AND dd = PQJ THEN
  157.             GOSUB coloring:
  158.             _PRINTSTRING (dayx + 25, weeky + 60), "Easter"
  159.         END IF
  160.         IF m = 4 AND dd > 23 AND weekday = 7 THEN
  161.             GOSUB coloring:
  162.             _PRINTSTRING (dayx + 25, weeky + 60), "Arbor"
  163.         END IF
  164.         IF m = 5 AND weekday = 0 AND dd > 14 AND dd < 22 THEN
  165.             GOSUB coloring:
  166.             _PRINTSTRING (dayx + 2, weeky + 60), "Armed Forces"
  167.         END IF
  168.         IF m = 5 AND weekday = 2 AND dd > 24 THEN
  169.             GOSUB coloring:
  170.             _PRINTSTRING (dayx + 15, weeky + 60), "Memorial"
  171.         END IF
  172.         IF m = 5 AND weekday = 1 AND dd > 7 AND dd < 15 THEN
  173.             GOSUB coloring:
  174.             _PRINTSTRING (dayx + 2, weeky + 60), "Mother's Day"
  175.         END IF
  176.         IF m = 6 AND weekday = 1 AND dd > 14 AND dd < 22 THEN
  177.             GOSUB coloring:
  178.             _PRINTSTRING (dayx + 2, weeky + 60), "Father's Day"
  179.         END IF
  180.         IF m = 6 AND dd = 14 THEN
  181.             GOSUB coloring:
  182.             _PRINTSTRING (dayx + 35, weeky + 60), "Flag"
  183.         END IF
  184.         IF m = 7 AND dd = 4 THEN
  185.             GOSUB coloring:
  186.             _PRINTSTRING (dayx + 2, weeky + 60), "Independence"
  187.         END IF
  188.         IF m = 9 AND weekday = 2 AND dd < 8 THEN
  189.             GOSUB coloring:
  190.             _PRINTSTRING (dayx + 27, weeky + 60), "Labor"
  191.         END IF
  192.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 2 THEN
  193.             GOSUB coloring:
  194.             _PRINTSTRING (dayx + 17, weeky + 60), "Columbus"
  195.         END IF
  196.         IF m = 10 AND dd = 31 THEN
  197.             GOSUB coloring:
  198.             _PRINTSTRING (dayx + 15, weeky + 60), "Halloween"
  199.         END IF
  200.         IF m = 11 AND dd = 11 THEN
  201.             GOSUB coloring:
  202.             _PRINTSTRING (dayx + 19, weeky + 60), "Veterans"
  203.         END IF
  204.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN
  205.             GOSUB coloring:
  206.             _PRINTSTRING (dayx + 2, weeky + 60), "Thanksgiving"
  207.         END IF
  208.         IF m = 12 AND dd = 25 THEN
  209.             GOSUB coloring:
  210.             _PRINTSTRING (dayx + 15, weeky + 60), "Christmas"
  211.         END IF
  212.         skip:
  213.         _FONT 16
  214.         _PRINTSTRING (dayx, weeky), dd$
  215.         _FONT 8
  216.         IF dd = days THEN _FONT 16: GOTO more2:
  217.     NEXT dayx
  218.     w = 25
  219. NEXT weeky
  220.  
  221. more2:
  222. _LIMIT 1000
  223. a$ = INKEY$
  224. IF a$ = CHR$(27) THEN CLS: PRINT: PRINT: PRINT "Goodbye.": END
  225. IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  226. IF a$ = " " THEN GOTO start:
  227. IF a$ = "p" OR a$ = "P" THEN
  228.     'printer prep (code copied and pasted from bplus Free Calendar Program)
  229.     YMAX = _HEIGHT: XMAX = _WIDTH
  230.     landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  231.     _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  232.     _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  233.     _PRINTIMAGE landscape&
  234.  
  235. IF a$ = CHR$(0) + CHR$(77) THEN
  236.     m = m + 1
  237.     IF m > 12 THEN
  238.         m = 1
  239.         yy = yy + 1
  240.     END IF
  241.     y = yy
  242.     IF y > 9999 THEN y = 1753
  243.     dd = 0
  244.     leap = 0
  245.     _DELAY .1
  246.     CLS
  247.     GOTO calculate:
  248. IF a$ = CHR$(0) + CHR$(75) THEN
  249.     m = m - 1
  250.     IF m < 1 THEN
  251.         m = 12
  252.         yy = yy - 1
  253.     END IF
  254.     y = yy
  255.     IF y < 1753 THEN y = 9999
  256.     dd = 0
  257.     leap = 0
  258.     _DELAY .1
  259.     CLS
  260.     GOTO calculate:
  261.  
  262. GOTO more2:
  263.  
  264. 'Color all Sundays and holidays
  265. coloring:
  266. LINE (dayx - 4, weeky - 9)-(dayx + 102, weeky + 68), _RGB32(255, 255, 127), BF: COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 127)
  267.  
  268.  
  269. 'Find the right date for Easter.
  270. PAQUES:
  271. PQM = INT(PQA / 100): PQ1 = PQA - PQM * 100: PQJ = INT(((PQA / 19 - INT(PQA / 19)) + .001) * 19)
  272. PQ2 = INT(PQM / 4): PQ3 = INT(((PQM / 4) - PQ2 + .001) * 4): PQ4 = INT((8 + PQM) / 25)
  273. PQ5 = INT((1 + PQM - PQ4 + .001) / 3): PQ4 = (15 + 19 * PQJ + PQM - PQ2 - PQ5 + .001) / 30: PQ4 = PQ4 - INT(PQ4)
  274. PQ4 = INT(PQ4 * 30): PQ5 = INT(PQ1 / 4): PQ6 = ((PQ1 / 4) - PQ5) * 4
  275. PQ7 = (32 + 2 * PQ3 + 2 * PQ5 - PQ4 - PQ6 + .001) / 7: PQ7 = (PQ7 - INT(PQ7)) * 7: PQ6 = (PQJ + 11 * PQ4 + 22 * PQ7) / 451
  276. PQ6 = INT(PQ6): PQ2 = (114 + PQ4 + PQ7 - 7 * PQ6) / 31: PQM = INT(PQ2): PQJ = INT((PQ2 - PQM + .001) * 31 + 1)
  277.  
  278.  
  279. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  280. saving:
  281. mo$ = STR$(m)
  282. mo$ = LTRIM$(RTRIM$(mo$))
  283. year$ = STR$(yy)
  284. year$ = LTRIM$(RTRIM$(year$))
  285. nm$ = mo$ + "-"
  286. nm$ = LTRIM$(RTRIM$(nm$))
  287. nm$ = nm$ + year$
  288. nm$ = LTRIM$(RTRIM$(nm$))
  289. SaveImage 0, nm$ 'saves entire program screen,"
  290. nm2$ = nm$ + ".bmp"
  291. nm2$ = LTRIM$(RTRIM$(nm2$))
  292. PRINT "                                           Saving"
  293. PRINT "                          "; nm2$; " has been saved to your computer."
  294. INPUT "                         Do you wish to make another calendar (Y/N)"; ag$
  295. IF LEFT$(ag$, 1) = "y" OR LEFT$(ag$, 1) = "Y" THEN GOTO start:
  296. PRINT "                         Goodbye."
  297.  
  298. weekdays:
  299.  
  300. 'This section gets the right weekday.
  301. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  302.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  303.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  304.     century = y MOD 100
  305.     zerocentury = y \ 100
  306.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  307.  
  308. 'This section saves the .bmp picture file.
  309. SUB SaveImage (image AS LONG, filename AS STRING)
  310.     bytesperpixel& = _PIXELSIZE(image&)
  311.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  312.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  313.     x& = _WIDTH(image&)
  314.     y& = _HEIGHT(image&)
  315.     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)
  316.     IF bytesperpixel& = 1 THEN
  317.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  318.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  319.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  320.         NEXT
  321.     END IF
  322.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  323.     lastsource& = _SOURCE
  324.     _SOURCE image&
  325.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  326.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  327.         r$ = ""
  328.         FOR px& = 0 TO x& - 1
  329.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  330.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  331.         NEXT px&
  332.         d$ = d$ + r$ + padder$
  333.     NEXT py&
  334.     _SOURCE lastsource&
  335.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  336.     b$ = b$ + d$ ' total file data bytes to create file
  337.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  338.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  339.     f& = FREEFILE
  340.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  341.     OPEN filename$ + ext$ FOR BINARY AS #f&
  342.     PUT #f&, , b$
  343.     CLOSE #f&
  344.  
Title: Re: Calendar Maker
Post by: Jack002 on September 19, 2019, 05:26:44 pm
I like the one on post #35 best. Very nice work. Bravo.
Title: Re: Calendar Maker
Post by: SierraKen on September 19, 2019, 09:43:36 pm
Thanks Jack. I'm working on letting people add up to 12 characters and spaces to any day of the month with the computer. But it won't save any info.
Title: Re: Calendar Maker
Post by: SierraKen on September 20, 2019, 01:11:38 am
Awesome I completed what I wanted! Now people can make a calendar with their own words on any date using their computer. You can also add info on the same days as holidays because it puts the text above the holiday names. And as before, you have the option of removing all the U.S. holidays as well. The holidays and any info you make also makes that day filled with yellow too so it's easy to see. Yesterday I printed one out with the new yellow on my b/w printer and it just makes a light shade of gray, which is perfect on a b/w printer. I tried for awhile to make it where people don't have to go from smallest date to highest date when they add stuff to the calendar, but with the loops I use for finding the certain days, it just wasn't compatible, as far as I know anyway. I'm sure someone might be able to change it someday, but this is good. I did though make the computer catch you if you did try to put info for like the 1st after the 15th and it tells you to start over again for that calendar. Everything is self-explanatory. The limit on info per-date is 12 letters, numbers, characters, or spaces.  Now everyone can make their own personal, typed out, monthly calendars any way they want to with their own information. Also, as I said earlier, there are no data files created or needed using this program, unless you wish to save one with it as a BMP picture. To save one, press the S key as it says above on the program. And to print one on the printer, press the P key once. Switching months with the arrow keys will not save your new added information if you come back to that month. This program can be used around the house or at a business. Enjoy.

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

Title: Re: Calendar Maker
Post by: TempodiBasic on September 20, 2019, 07:35:27 am
Oh Thanks SierraKen

It seems cooler than first one

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

but remember to print o save as image before change mounth by keyboard!
Title: Re: Calendar Maker
Post by: STxAxTIC on September 20, 2019, 09:48:17 am
Great work Ken - after this thread cools down for a minute, this prog will end up in Samples.
Title: Re: Calendar Maker
Post by: SierraKen on September 20, 2019, 01:23:18 pm
Thanks you 2!!! Would love it in the Samples area. I strongly believe this is the best program I've ever made out of programming in BASIC since the 80's.
Title: Re: Calendar Maker
Post by: SierraKen on September 20, 2019, 04:14:40 pm
I just tried to see if people can remake a day's info after making the same day's info and it just keeps the first one. Probably because I used an array on the days and the day of the edit has to match the day it numbers, etc. so since it was already done, it went to the next day instead of backtracking to edit again. So I just added one line of text saying if you messed up, just make a new calendar.

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