Author Topic: Weekday Finder  (Read 9097 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Weekday Finder
« Reply #15 on: August 04, 2019, 02:05:26 am »
Code: QB64: [Select]
  1. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  2.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  3.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  4.     century = yyyy MOD 100
  5.     zerocentury = yyyy \ 100
  6.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  7.     SELECT CASE result
  8.         CASE 0: Day$ = "Saturday"
  9.         CASE 1: Day$ = "Sunday"
  10.         CASE 2: Day$ = "Monday"
  11.         CASE 3: Day$ = "Tuesday"
  12.         CASE 4: Day$ = "Wednesday"
  13.         CASE 5: Day$ = "Thursday"
  14.         CASE 6: Day$ = "Friday"
  15.     END SELECT
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Weekday Finder
« Reply #16 on: August 04, 2019, 04:12:10 am »
My program based on the Julian calendar seems to be better, I think ?
Why not yes ?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #17 on: August 04, 2019, 08:40:53 am »

Well, lol, this program turned out to be trash most likely. I was working on a calendar maker all day on Saturday and the evening, almost got it done, when I noticed that something was wrong with May of the year 2020. It kept messing up on me a lot. So after many hours of trying to fix it, I wondered to myself if it was that old equation that this Weekday Finder uses, and yes it is. Both programs can't calculate a month that falls onto 6 weeks, for example, May 2020 starts on a Friday and ends on a Sunday, so it's 6 weeks needed and it just can't handle that. I don't know what the professionals use for their equations to find the days of the week, but I'm giving up on this for now. So, if you have this Weekly Finder, please delete it with my apologies. I guess that serves me right for using stuff I find online that I don't know 100% of.


(Dang! 2 replies I didn't see since this post above and my reply below.)

I don't think the problem you describe is the fault of the formula, it is giving you the proper weekday name isn't it? (I haven't checked.)

Months that span over 6 weeks 4 full + 2 partial are always trouble for calendar makers, who wants to waste all that paper space for 1 or 2 days on each side of the 4 full weeks, yuck.

Here is my attempt and Pete's old code:
https://www.qb64.org/forum/index.php?topic=855.msg100586#msg100586
« Last Edit: August 04, 2019, 08:43:43 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #18 on: August 04, 2019, 09:12:19 am »
Code: QB64: [Select]
  1. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  2.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  3.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  4.     century = yyyy MOD 100
  5.     zerocentury = yyyy \ 100
  6.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  7.     SELECT CASE result
  8.         CASE 0: Day$ = "Saturday"
  9.         CASE 1: Day$ = "Sunday"
  10.         CASE 2: Day$ = "Monday"
  11.         CASE 3: Day$ = "Tuesday"
  12.         CASE 4: Day$ = "Wednesday"
  13.         CASE 5: Day$ = "Thursday"
  14.         CASE 6: Day$ = "Friday"
  15.     END SELECT

OK, fixed
Code: QB64: [Select]
  1. _TITLE "GetDay$ function test."
  2.     PRINT "(don't forget 0's, just enter to quit)"
  3.     INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  4.     yyyy = VAL(MID$(yymmdd$, 1, 4))
  5.     mm = VAL(MID$(yymmdd$, 6, 2))
  6.     dd = VAL(MID$(yymmdd$, 9, 2))
  7.     PRINT GetDay$(mm, dd, yyyy)
  8.     PRINT
  9. LOOP UNTIL yymmdd$ = ""
  10.  
  11. 'Steve (SAM) function fix for Ken
  12. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  13.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  14.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  15.     century = yyyy MOD 100
  16.     zerocentury = yyyy \ 100
  17.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  18.     SELECT CASE result
  19.         CASE 0: Day$ = "Saturday"
  20.         CASE 1: Day$ = "Sunday"
  21.         CASE 2: Day$ = "Monday"
  22.         CASE 3: Day$ = "Tuesday"
  23.         CASE 4: Day$ = "Wednesday"
  24.         CASE 5: Day$ = "Thursday"
  25.         CASE 6: Day$ = "Friday"
  26.     END SELECT
  27.     GetDay$ = Day$
  28.  
« Last Edit: August 04, 2019, 09:18:47 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #19 on: August 04, 2019, 10:24:03 am »
Checking KenDay$ and GetDay$ for next 10 Christmas dates, yeah Ken you are a bit off:
Code: QB64: [Select]
  1. _TITLE "Ken Day test" 'B+ started 2019-08-04 Sunday
  2. SCREEN _NEWIMAGE(400, 760, 32)
  3. FOR yyyy = 2019 TO 2029
  4.     'PRINT "(don't forget 0's, just enter to quit)"
  5.     'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  6.     'yyyy = VAL(MID$(yymmdd$, 1, 4))
  7.     'mm = VAL(MID$(yymmdd$, 6, 2))
  8.     'dd = VAL(MID$(yymmdd$, 9, 2))
  9.     PRINT "Christmas"; yyyy
  10.     PRINT "  Ken day = "; kenDay$(12, 25, yyyy)
  11.     PRINT "Steve day = "; GetDay$(12, 25, yyyy)
  12.     PRINT
  13.  
  14. FUNCTION kenDay$ (yyyy, mm, dd)
  15.  
  16.     'Months
  17.     'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  18.     mm = mm - 2  ' < edit: still off
  19.     IF mm = 1 THEN mm = 11: yyyy = yyyy - 1
  20.     IF mm = 2 THEN mm = 12: yyyy = yyyy - 1
  21.  
  22.     'Full Year.
  23.     y$ = STR$(yyyy)
  24.  
  25.     'Last 2 digits of year.
  26.     yy$ = RIGHT$(y$, 2)
  27.     yy = VAL(yy$)
  28.  
  29.     'Century
  30.     c$ = LEFT$(y$, 3)
  31.     c = VAL(c$)
  32.  
  33.     'Here is Zeller's Rule equation.
  34.  
  35.     weekday = (dd + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  36.  
  37.     IF weekday = 0 THEN w$ = "Sunday"
  38.     IF weekday = 1 THEN w$ = "Monday"
  39.     IF weekday = 2 THEN w$ = "Tuesday"
  40.     IF weekday = 3 THEN w$ = "Wednesday"
  41.     IF weekday = 4 THEN w$ = "Thursday"
  42.     IF weekday = 5 THEN w$ = "Friday"
  43.     IF weekday = 6 THEN w$ = "Saturday"
  44.     kenDay$ = w$
  45.  
  46. 'Steve (SAM) function fix for Ken
  47. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  48.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  49.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  50.     century = yyyy MOD 100
  51.     zerocentury = yyyy \ 100
  52.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  53.     SELECT CASE result
  54.         CASE 0: Day$ = "Saturday"
  55.         CASE 1: Day$ = "Sunday"
  56.         CASE 2: Day$ = "Monday"
  57.         CASE 3: Day$ = "Tuesday"
  58.         CASE 4: Day$ = "Wednesday"
  59.         CASE 5: Day$ = "Thursday"
  60.         CASE 6: Day$ = "Friday"
  61.     END SELECT
  62.     GetDay$ = Day$
  63.  
  64.  

EDIT: fix line that should of (hee hee) read (mm = mm - 2)

Update: Big screw up with misaligned arguments when testing KenDay$, my apologies. See new test below...
xmas 10 years.PNG
* xmas 10 years.PNG (Filesize: 17.56 KB, Dimensions: 503x354, Views: 289)
« Last Edit: August 04, 2019, 12:34:55 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #20 on: August 04, 2019, 11:28:49 am »
Wow so much help and so much to choose from! LOL Plus after I turned off my computer last night I remembered that I should have posted that I will try the one euklides posted. And since I have never used a Function before, I will try both Euk's and B+'s and see which one will work easiest on my program later today. Thanks everyone :))) The one euklides posted works fine for May 2020, I did a quick test on it. Will try B+'s soon..... ahh I see B+ is using the Function as well.
« Last Edit: August 04, 2019, 11:45:44 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #21 on: August 04, 2019, 11:58:00 am »
Since B+ spent so much time helping me, I'll use his and SmMcNeill's, and try my hands at a Function. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #22 on: August 04, 2019, 12:22:40 pm »
Dang it, I see another screw up I did with testing Ken's function, misaligned arguments, blah! :(

Be right back!

Big apologies to Ken!

Ken, your days for Christmas for 10 years are matching up with Steve's, I screwed up the test by misaligning the arguments to the parameters ie I used the same order of month, day, year as I used in Steve's but I wrote the translation of your code into the Function with y, m, d order.

Here is revised test:
Code: QB64: [Select]
  1. _TITLE "Ken Day test" 'B+ started 2019-08-04 Sunday
  2. SCREEN _NEWIMAGE(400, 760, 32)
  3. FOR yyyy = 2019 TO 2029
  4.     'PRINT "(don't forget 0's, just enter to quit)"
  5.     'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  6.     'yyyy = VAL(MID$(yymmdd$, 1, 4))
  7.     'mm = VAL(MID$(yymmdd$, 6, 2))
  8.     'dd = VAL(MID$(yymmdd$, 9, 2))
  9.     PRINT "Christmas"; yyyy
  10.     PRINT "  Ken day = "; kenDay$(12, 25, yyyy)
  11.     PRINT "Steve day = "; GetDay$(12, 25, yyyy)
  12.     PRINT
  13.  
  14. FUNCTION kenDay$ (m AS INTEGER, d AS INTEGER, y AS INTEGER) ' now same order as GetDay$ function
  15.     mm = m 'get copies so don't change incoming when out going
  16.     dd = d
  17.     yyyy = y
  18.     'Months
  19.     'The months start on March 1 so Leap Year will be the last day of the year, which is why Jan. and Feb. are actually the year before.
  20.     mm = mm - 2 ' < edit: still off
  21.     IF mm = 1 THEN mm = 11: yyyy = yyyy - 1
  22.     IF mm = 2 THEN mm = 12: yyyy = yyyy - 1
  23.  
  24.     'Full Year.
  25.     y$ = STR$(yyyy)
  26.  
  27.     'Last 2 digits of year.
  28.     yy$ = RIGHT$(y$, 2)
  29.     yy = VAL(yy$)
  30.  
  31.     'Century
  32.     c$ = LEFT$(y$, 3)
  33.     c = VAL(c$)
  34.  
  35.     'Here is Zeller's Rule equation.
  36.  
  37.     weekday = (dd + INT(((13 * mm) - 1) / 5) + yy + INT(yy / 4) + INT(c / 4) - (2 * c)) MOD 7
  38.  
  39.     IF weekday = 0 THEN w$ = "Sunday"
  40.     IF weekday = 1 THEN w$ = "Monday"
  41.     IF weekday = 2 THEN w$ = "Tuesday"
  42.     IF weekday = 3 THEN w$ = "Wednesday"
  43.     IF weekday = 4 THEN w$ = "Thursday"
  44.     IF weekday = 5 THEN w$ = "Friday"
  45.     IF weekday = 6 THEN w$ = "Saturday"
  46.     kenDay$ = w$
  47.  
  48. 'Steve (SAM) function fix for Ken
  49. FUNCTION GetDay$ (mm, dd, yyyy) 'use 4 digit year
  50.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  51.     IF mm < 3 THEN mm = mm + 12: yyyy = yyyy - 1
  52.     century = yyyy MOD 100
  53.     zerocentury = yyyy \ 100
  54.     result = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  55.     SELECT CASE result
  56.         CASE 0: Day$ = "Saturday"
  57.         CASE 1: Day$ = "Sunday"
  58.         CASE 2: Day$ = "Monday"
  59.         CASE 3: Day$ = "Tuesday"
  60.         CASE 4: Day$ = "Wednesday"
  61.         CASE 5: Day$ = "Thursday"
  62.         CASE 6: Day$ = "Friday"
  63.     END SELECT
  64.     GetDay$ = Day$
  65.  
« Last Edit: August 04, 2019, 12:33:09 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #23 on: August 04, 2019, 12:23:36 pm »
Awesome I fixed it!!! Thanks guys!!! Instead of a Function I turned it into a SUB because all I needed was variables and strings. I'm almost done now with my Calendar Maker. I just have to adjust some things first, hopefully will be done today and I'll make a new forum topic for it. It will have all U.S. Federal Holidays as well, which I already added. Plus it will give the user the ability to save it as a JPG and also print it on the printer. The funny thing is, I'm still getting used to the printer and I accidentally (again) printed a whole sheet of black. lol So thankfully QB64 has the ability to save the screen and that's what I'm going to do, and then print it after loading the JPG. Oh, and it only makes 1 month at a time.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #24 on: August 04, 2019, 12:26:35 pm »
Oh Wow B+... I'll have to see it later on, I have to get going for a few hours. I might have fixed it myself, I messed around with it a little bit to make the SUB and also use Y instead of YYYY and weekday instead of that other one you had for each weekday number. See you later today, thanks again for the help!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #25 on: August 04, 2019, 12:28:35 pm »
Oh, and since you are probably curious, this is what I have so far for the Calendar Maker... it's VERY VERY VERY rough so far, and NOT finished, but getting closer. :)

Code: QB64: [Select]
  1.  
  2. 'Something is wrong with weekday variable, it goes into the negative when 6 "weeks" are needed on the loop.
  3.  
  4.  
  5. _TITLE "Calendar Maker"
  6. start:
  7. dd = 0
  8. leap = 0
  9. SCREEN _NEWIMAGE(800, 600, 32)
  10. PRINT "                       Monthly Calendar Maker"
  11. PRINT "                           By Ken G."
  12. PRINT "This program will make a calendar for the year and month you want."
  13. PRINT "It will also name the U.S. Federal Holidays on their days."
  14. INPUT "Type the year here: ", y
  15. again2:
  16. INPUT "Type the month here: ", m
  17. IF m < 1 OR m > 12 THEN PRINT "1-12 only, try again.": GOTO again2:
  18.  
  19. IF m = 1 THEN month$ = " January"
  20. IF m = 2 THEN month$ = "February"
  21. IF m = 3 THEN month$ = "  March"
  22. IF m = 4 THEN month$ = "  April"
  23. IF m = 5 THEN month$ = "  May"
  24. IF m = 6 THEN month$ = "  June"
  25. IF m = 7 THEN month$ = "  July"
  26. IF m = 8 THEN month$ = " August"
  27. IF m = 9 THEN month$ = "September"
  28. IF m = 10 THEN month$ = " October"
  29. IF m = 11 THEN month$ = "November"
  30. IF m = 12 THEN month$ = "December"
  31.  
  32. IF m <> 2 THEN GOTO nex:
  33. 'Calculate to see if it's a Leap Year.
  34. IF y / 400 = INT(y / 400) THEN leap = 1: GOTO more:
  35. IF y / 4 = INT(y / 4) THEN leap = 1
  36. IF y / 100 = INT(y / 100) THEN leap = 0
  37. more:
  38. IF leap = 1 THEN days = 29
  39. IF leap = 0 THEN days = 28
  40. GOTO weekday:
  41. nex:
  42. IF m = 1 THEN days = 31
  43. IF m = 3 THEN days = 31
  44. IF m = 4 THEN days = 30
  45. IF m = 5 THEN days = 31
  46. IF m = 6 THEN days = 30
  47. IF m = 7 THEN days = 31
  48. IF m = 8 THEN days = 31
  49. IF m = 9 THEN days = 30
  50. IF m = 10 THEN days = 31
  51. IF m = 11 THEN days = 30
  52. IF m = 12 THEN days = 31
  53. weekday:
  54. k = 1
  55. mm = m
  56. yy = y
  57. GetDay mm, dd, y, weekday
  58.  
  59. 'This section makes the calendar.
  60. make:
  61. LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), BF
  62. COLOR _RGB(0, 0, 0), _RGB(255, 255, 255)
  63. LOCATE 1, 47: PRINT month$
  64. LOCATE 2, 48: PRINT yy
  65.  
  66. FOR x = 20 TO 780 STEP 108
  67.     LINE (x, 100)-(x, 580), _RGB32(0, 0, 0)
  68. FOR z = 100 TO 580 STEP 80
  69.     LINE (16, z)-(780, z), _RGB32(0, 0, 0)
  70.  
  71. LOCATE 5, 8: PRINT "SUNDAY"
  72. LOCATE 5, 21: PRINT "MONDAY"
  73. LOCATE 5, 34: PRINT "TUESDAY"
  74. LOCATE 5, 47: PRINT "WEDNESDAY"
  75. LOCATE 5, 60: PRINT "THURSDAY"
  76. LOCATE 5, 75: PRINT "FRIDAY"
  77. LOCATE 5, 87: PRINT "SATURDAY"
  78. w = (weekday * 13) + 8
  79. FOR week = 8 TO 59 STEP 5
  80.     FOR day = w TO 91 STEP 13
  81.         dd = dd + 1
  82.         k = dd
  83.         GetDay mm, dd, y, weekday
  84.         IF weekday < 4 THEN LOCATE week, day - 1: PRINT dd
  85.         IF weekday >= 4 THEN LOCATE week, day + 1: PRINT dd
  86.         IF m = 1 AND dd = 1 THEN LOCATE week + 2, day - 1: PRINT "New Years"
  87.         IF m = 1 AND weekday = 1 AND dd > 16 AND dd < 24 THEN LOCATE week + 4, day - 1: PRINT "MLK Jr. Day"
  88.         IF m = 2 AND weekday = 1 AND dd > 16 AND dd < 24 THEN LOCATE week + 4, day - 1: PRINT "Pres. Day"
  89.         IF m = 5 AND weekday = 1 AND dd > 24 THEN LOCATE week + 4, day - 1: PRINT "Mem. Day"
  90.         IF m = 7 AND dd = 4 THEN LOCATE week + 4, day - 1: PRINT "Independence"
  91.         IF m = 9 AND weekday = 1 AND dd < 8 THEN LOCATE week + 2, day - 1: PRINT "Labor Day"
  92.         IF m = 10 AND dd > 9 AND dd < 16 AND weekday = 1 THEN LOCATE week + 4, day - 1: PRINT "Columbus"
  93.         IF m = 11 AND dd = 11 THEN LOCATE week + 4, day - 1: PRINT "Veterans Day"
  94.         IF m = 11 AND dd > 21 AND dd < 29 AND weekday = 5 THEN LOCATE week + 4, day - 1: PRINT "Thanksgving"
  95.         IF m = 12 AND dd = 25 THEN LOCATE week + 4, day - 1: PRINT "Christmas"
  96.         IF dd = days THEN GOTO more2:
  97.     NEXT day
  98.     w = 7
  99. NEXT week
  100.  
  101.  
  102. more2:
  103. LOCATE 29, 1: INPUT "Press Enter to go back to menu.", a$
  104. GOTO start:
  105.  
  106.  
  107.  
  108.  
  109.  
  110. 'This section saves the calendar to a JPG file.
  111.  
  112. SaveImage 0, "screenshot" 'saves entire program screen as "screenshot.bmp"
  113.  
  114. weekdays:
  115. 'DO
  116. '    PRINT "(don't forget 0's, just enter to quit)"
  117. 'INPUT "  Enter yyyy-mm-dd date format: "; yymmdd$
  118. 'yyyy = VAL(MID$(yymmdd$, 1, 4))
  119. 'mm = VAL(MID$(yymmdd$, 6, 2))
  120. 'dd = VAL(MID$(yymmdd$, 9, 2))
  121. 'PRINT GetDay$(mm, dd, yyyy)
  122. 'PRINT
  123. 'LOOP UNTIL yymmdd$ = ""
  124. 'RETURN
  125.  
  126. 'Steve (SAM) function fix for Ken
  127. SUB GetDay (mm, dd, y, weekday) 'use 4 digit year
  128.     'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
  129.     IF mm < 3 THEN mm = mm + 12: y = y - 1
  130.     century = y MOD 100
  131.     zerocentury = y \ 100
  132.     weekday = (dd + INT(13 * (mm + 1) / 5) + century + INT(century / 4) + INT(zerocentury / 4) + 5 * zerocentury) MOD 7
  133.     SELECT CASE weekday
  134.         CASE 0: Day$ = "Saturday"
  135.         CASE 1: Day$ = "Sunday"
  136.         CASE 2: Day$ = "Monday"
  137.         CASE 3: Day$ = "Tuesday"
  138.         CASE 4: Day$ = "Wednesday"
  139.         CASE 5: Day$ = "Thursday"
  140.         CASE 6: Day$ = "Friday"
  141.     END SELECT
  142.  
  143.  
  144.  
  145.  
  146. SUB SaveImage (image AS LONG, filename AS STRING)
  147.     bytesperpixel& = _PIXELSIZE(image&)
  148.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  149.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  150.     x& = _WIDTH(image&)
  151.     y& = _HEIGHT(image&)
  152.     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)
  153.     IF bytesperpixel& = 1 THEN
  154.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  155.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  156.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  157.         NEXT
  158.     END IF
  159.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  160.     lastsource& = _SOURCE
  161.     _SOURCE image&
  162.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  163.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  164.         r$ = ""
  165.         FOR px& = 0 TO x& - 1
  166.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  167.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  168.         NEXT px&
  169.         d$ = d$ + r$ + padder$
  170.     NEXT py&
  171.     _SOURCE lastsource&
  172.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  173.     b$ = b$ + d$ ' total file data bytes to create file
  174.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  175.     IF LCASE$(RIGHT$(filename$, 4)) <> ".jpg" THEN ext$ = ".jpg"
  176.     f& = FREEFILE
  177.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  178.     OPEN filename$ + ext$ FOR BINARY AS #f&
  179.     PUT #f&, , b$
  180.     CLOSE #f&
  181.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Weekday Finder
« Reply #26 on: August 04, 2019, 08:22:28 pm »
Hi Ken,

I have tested more dates with code in reply #19, though it gets Christmas correct for next 10 years, it misses with March 2019 dates.

The calendars for 2019 all do seem to start and end on correct day. You might control labels better with _PRINTSTRING which locates to the pixel instead of character cell rows and columns, start text just below and right of top left line intersects.
« Last Edit: August 04, 2019, 08:23:57 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Weekday Finder
« Reply #27 on: August 05, 2019, 01:41:25 am »
Thanks B+, I'm 99.9% sure that I'm finished with the Calendar Maker. I'm starting a new forum topic now only for that program.