Author Topic: CalenTools a collection of calendar stuff  (Read 2572 times)

0 Members and 1 Guest are viewing this topic.

Offline redwdc

  • Newbie
  • Posts: 4
    • View Profile
CalenTools a collection of calendar stuff
« on: January 06, 2022, 07:38:59 pm »
Some of this is quite old.  Some I wrote in the past couple of months.

I'm open to any comments. I know the coding is a bit simplistic and rough around the edges so to speak.

I just found out that my ASCII boxes didn't survive the copy and paste process. Oh well.

Oh, thanks to Jack for the help with the convert to Julian Day algorithm.

Code: QB64: [Select]
  1. Dim Shared FDay$
  2. Dim Shared MoNa$
  3. Dim Shared WkDa$
  4. Dim Shared xerr
  5.  
  6. _Title "CalenTools"
  7.  
  8. xerr = 0
  9. FDay$ = ""
  10.  
  11. filenum = FreeFile
  12. If _FileExists("calentools.dat") Then
  13.     Open "calentools.dat" For Input As #filenum
  14.     Input #filenum, FDay$
  15.     Close #filenum
  16.  
  17. Main_Menu
  18. Sub Main_Menu
  19.     Cls
  20.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  21.     Print "º                                  Main Menu                                   º"
  22.     Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
  23.     Print "º 0. CalenTools only works for years between 1583 and 3266 inclusive.          º"
  24.     Print "º    See why, and read about Julian Day numbers and ISO week numbers.          º"
  25.     Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
  26.     Print "º 1. Add or Subtract days from a date.                                         º"
  27.     Print "º 2. Calendars for a month and/or a year.                                      º"
  28.     Print "º 3. Day of week e.g., 1968-03-17 was a Sunday.                                º"
  29.     Print "º 4. Day of week repetitive e.g., what years following 1968 was 03-17 a Sunday.º"
  30.     Print "º 5. Day of year number from date e.g., 1968-03-17 was 77th day of the year.   º"
  31.     Print "º 6. Date from day of year number e.g., in 1968 77th day was 03-17.            º"
  32.     Print "º 7. Difference between two dates in Years Months and Days.                    º"
  33.     Print "º 8. Find Easter day.                                                          º"
  34.     Print "º 9. Date to Julian Day number.                                                º"
  35.     Print "º A. Julian Day number to date.                                                º"
  36.     Print "º B. Was/is/will it be a Leap Year.                                            º"
  37.     Print "º c. Week number of the year (this is ISO week numbers).                       º"
  38.     Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
  39.     Print "º Q. To Quit.  You can also quit from any other prompt by entering Q.          º"
  40.     Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
  41.     Print "º Enter the number/letter of your choice:                                      º"
  42.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  43.     Locate 22, 42: Input " ", q$:
  44.     q$ = LCase$(q$)
  45.     Select Case q$
  46.         Case "0": Why_Dates
  47.         Case "1": Start_ASD
  48.         Case "2": Start_Cals
  49.         Case "3": Start_DoW
  50.         Case "4": Start_DoWR
  51.         Case "5": Start_DoY
  52.         Case "6": Start_RDoY
  53.         Case "7": Start_DYMD
  54.         Case "8": Start_Easter
  55.         Case "9": Start_Date_to_JD
  56.         Case "a": Start_JD_to_Date
  57.         Case "b": Start_Leap_Year
  58.         Case "c": Start_WkNo
  59.         Case "q": Done
  60.         Case Else: Main_Menu
  61.     End Select
  62.  
  63. Sub Start_ASD
  64.     Cls
  65.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  66.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Add or Subtract Days  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  67.     Print
  68.     Input " Are you Adding to or Subtracting from a date (A/S)"; q$
  69.     q$ = LCase$(q$)
  70.  
  71.     If q$ = "a" Then
  72.         OpWd$ = " plus "
  73.         xWd$ = "add"
  74.         yWd$ = "add to"
  75.     ElseIf q$ = "s" Then
  76.         OpWd$ = " minus "
  77.         xWd$ = "subtrtact"
  78.         yWd$ = "subtrtact from"
  79.     ElseIf q$ = "q" Then
  80.         Done
  81.     Else
  82.         Print " You must enter 'A' for adding or 'S' for subtracting."
  83.         Input " Press 'Enter' to continue."; q$
  84.         If LCase$(q$) = "q" Then Done
  85.         Start_ASD
  86.     End If
  87.  
  88.     Print " Enter the number of days you want to "; xWd$; ":";: Input " ", ND$
  89.     If LCase$(ND$) = "q" Then Done
  90.     ND = Val(ND$)
  91.  
  92.     Print " Enter date to "; yWd$; " (yyyy-mm-dd)";: Input " ", Dt$
  93.     If LCase$(Dt$) = "q" Then Done
  94.  
  95.     Date_to_YMD
  96.     If xerr = 1 Then xerr = 0: Start_ASD
  97.  
  98.     Date_to_JD
  99.     JDs = JD
  100.     If LCase$(q$) = "a" Then
  101.         JD = JDs + ND
  102.     Else
  103.         JD = JDs - ND
  104.     End If
  105.     JD_to_Date
  106.  
  107.     Zellers
  108.  
  109.     Day_Names_Long
  110.  
  111.     YMD_to_Str
  112.  
  113.     Print: Print
  114.     Print " "; Dt$; RTrim$(OpWd$); ND; "days is "; WkDa$; ","; y$; "-" + LTrim$(m$); "-"; LTrim$(d$)
  115.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  116.     Again: Start_ASD
  117.  
  118. Sub Start_Cals
  119.     Cls
  120.     If FDay$ = "s" Or FDay$ = "m" Then
  121.         Cals
  122.     Else
  123.         Get_1st_Day
  124.     End If
  125.  
  126. Sub Get_1st_Day
  127.     Cls
  128.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  129.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Calendars  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  130.     Print
  131.     Print " Do you wish weeks to start on Sunday or Monday.  Your choice will be"
  132.     Print " remembered until you quit, unless you change it in the Calendar menu."
  133.     Input " (S/M): ", FDay$
  134.     FDay$ = LCase$(FDay$)
  135.     If FDay$ = "q" Then
  136.         Done
  137.     ElseIf FDay$ = "s" Or FDay$ = "m" Then
  138.         Cals
  139.     Else
  140.         Get_1st_Day
  141.     End If
  142.  
  143. Sub Cals:
  144.     Cls
  145.     Tday = Val(Mid$(Date$, 4, 2))
  146.     Locate 1, 18: Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  147.     Locate 2, 18: Print "º                 Calendar                  º"
  148.     Locate 3, 18: Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
  149.     Locate 4, 18: Print "º 1. This month                             º"
  150.     Locate 5, 18: Print "º 2. Another month this year                º"
  151.     Locate 6, 18: Print "º 3. A month in a dIfferent year            º"
  152.     Locate 7, 18: Print "º 4. Calendar of this year                  º"
  153.     Locate 8, 18: Print "º 5. Calendar of another year               º"
  154.     Locate 9, 18: Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
  155.     Locate 10, 18: Print "º C. Change first day of week               º"
  156.     Locate 11, 18: Print "º M. Main Menu                              º"
  157.     Locate 12, 18: Print "º S. Save 1st day of week to disc           º"
  158.     Locate 13, 18: Print "ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ"
  159.     Locate 14, 18: Print "º Q. To Quit CalenTools                     º"
  160.     Locate 15, 18: Print "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹"
  161.     Locate 16, 18: Print "º Enter the number/letter of your choice:   º"
  162.     Locate 17, 18: Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  163.     Locate 16, 59: Input " ", q$
  164.     q$ = LCase$(q$)
  165.     Select Case q$
  166.         Case "1"
  167.             y = Val(Right$(Date$, 4))
  168.             m = Val(Left$(Date$, 2))
  169.             Make_Month
  170.         Case "2"
  171.             Locate 18, 19: Input " Enter month mm: ", m$
  172.             If LCase$(q$) = "q" Then Done
  173.             m = Val(m$)
  174.             If m < 1 Or m > 12 Then
  175.                 Print " Enter a month number between 1 and 12."
  176.                 Input " Press 'Enter' to continue. ", q$
  177.                 If LCase$(q$) = "q" Then Done
  178.                 Cals
  179.             End If
  180.             y = Val(Right$(Date$, 4))
  181.             Make_Month
  182.         Case "3"
  183.             Locate 18, 19: Input " Enter a year and month yyyy-mm: ", Dt$
  184.             If LCase$(Dt$) = "q" Then Done
  185.             If Len(Dt$) <> 7 Then
  186.                 Print " Enter a 4 digit year '-' 2 digit month, e.g., yyyy-mm"
  187.                 Input " Press 'Enter' to continue. ", q$
  188.                 Cals
  189.             End If
  190.             y = Val(Left$(Dt$, 4))
  191.             m = Val(Right$(Dt$, 2))
  192.             If m < 1 Or m > 12 Or y < 1583 Or y > 3266 Then
  193.                 Print " You must enter year from 1583 to 3266 and a month from 1 - 12."
  194.                 Input " Press 'Enter' to continue. ", q$
  195.                 If LCase$(q$) = "q" Then Done
  196.                 Cals
  197.             End If
  198.             Make_Month
  199.         Case "4"
  200.             y = Val(Right$(Date$, 4))
  201.             Make_Year
  202.         Case "5"
  203.             Locate 18, 19: Input " Enter a year yyyy ", y$
  204.             If LCase$(y$) = "q" Then Done
  205.             y = Val(y$)
  206.             If Len(y) <> 4 Or y < 1583 Or y > 3266 Then
  207.                 Print
  208.                 Print " Enter a year between 1583 and 3266."
  209.                 Input " Press 'Enter' to continue. ", q$
  210.                 If LCase$(q$) = "q" Then Done
  211.                 Cals
  212.             End If
  213.             Make_Year
  214.         Case "c"
  215.             Get_1st_Day: Cals
  216.         Case "m"
  217.             Main_Menu
  218.         Case "s"
  219.             Save_1st_Day
  220.         Case "q"
  221.             Done
  222.         Case Else
  223.             Cals
  224.     End Select
  225.     If Val(q$) < 4 Then row = row + 1
  226.     Locate row - 1, 1: Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  227.     Again: Start_Cals
  228.  
  229. Sub Make_Month
  230.     Cls
  231.     Print
  232.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  233.     row = 3
  234.     col = 30
  235.     d = 1
  236.     Make_Cal
  237.  
  238. Sub Make_Year
  239.     Cls
  240.     Print
  241.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  242.     row = 3
  243.     m = 1
  244.     d = 1
  245.     nm = m
  246.     For mr = 1 To 4
  247.         col = 5
  248.         For cm = 1 To 3
  249.             Make_Cal
  250.             nm = nm + 1
  251.             d = 1
  252.             m = nm
  253.             row = row - 8
  254.             col = col + 25
  255.         Next cm
  256.         row = row + 9
  257.     Next mr
  258.  
  259. Sub Make_Cal
  260.     TDay = Val(Mid$(Date$, 4, 2))
  261.     Zellers
  262.     If FDay$ = "m" Then dow = dow - 1: If dow < 0 Then dow = 6
  263.     n2 = dow
  264.  
  265.     Day_Of_Year
  266.     n1 = doy: m1 = m
  267.     m = m + 1
  268.  
  269.     If m > 12 Then
  270.         n3 = 31
  271.     Else
  272.         Day_Of_Year: n3 = doy - n1
  273.     End If
  274.  
  275.     m = m1
  276.     Month_Names_Long
  277.     Color 7, 0: Locate row, col + 1: Print MoNa$; " "; y
  278.     row = row + 1
  279.  
  280.     If FDay$ = "m" Then
  281.         Color 7, 0: Locate row, col + 1: Print "Mo Tu We Th Fr"
  282.         Color 12, 0: Locate row, col + 16: Print "Sa Su": Color 7, 0
  283.     Else
  284.         Color 12, 0: Locate row, col + 1: Print "Su"
  285.         Color 7, 0: Locate row, col + 4: Print "Mo Tu We Th Fr"
  286.         Color 12, 0: Locate row, col + 19: Print "Sa": Color 7, 0
  287.     End If
  288.  
  289.     row = row + 1
  290.     dn = 0
  291.  
  292.     ' This sets up printing "Gray Days"
  293.     DM = m1
  294.     Days_In_Month
  295.     GD = dlm - n2 + 1
  296.     aGD = 1
  297.  
  298.     ' Print the calendars
  299.     For i = 1 To 6
  300.         C = col
  301.         g = 1
  302.         wkd = 0
  303.         For j = 1 To 7
  304.             s = C
  305.             If g < n2 + 1 And i = 1 Or dn >= n3 Then
  306.  
  307.                 If dn < 1 Then
  308.                     Color 8, 0: Locate row, s: Print GD
  309.                 ElseIf dn >= n3 Then
  310.                     If aGD <= 9 Then s = s + 1
  311.                     Color 8, 0: Locate row, s: Print aGD
  312.                     Color 7, 0
  313.                     aGD = aGD + 1
  314.                 End If
  315.  
  316.             ElseIf m1 = Val(Left$(Date$, 2)) And y = Val(Right$(Date$, 4)) And dn + 1 = TDay Then
  317.                 dn = dn + 1
  318.                 If dn <= 9 Then s = s + 1
  319.                 Color 11, 0: Locate row, s: Print dn
  320.             ElseIf (FDay$ = "s" And wkd = 0 Or wkd = 6) Or (FDay$ = "m" And wkd >= 5 Or wkd = 6) Then
  321.                 dn = dn + 1
  322.                 If dn <= 9 Then s = s + 1
  323.                 Color 12, 0: Locate row, s: Print dn: Color 7, 0
  324.             ElseIf m1 <> Val(Left$(Date$, 2)) Or y <> Val(Right$(Date$, 4)) Or dn + 1 <> TDay Then
  325.                 dn = dn + 1
  326.                 If dn <= 9 Then s = s + 1
  327.                 Color 7, 0: Locate row, s: Print dn
  328.             End If
  329.             wkd = wkd + 1
  330.             C = C + 3
  331.             g = g + 1
  332.             GD = GD + 1
  333.         Next j
  334.         row = row + 1
  335.     Next i
  336.  
  337. Sub Start_DoW
  338.     Cls
  339.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  340.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Day of Week  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  341.     Print
  342.     Print " Enter date to check (yyyy-mm-dd)";: Input Dt$
  343.     If LCase$(Dt$) = "q" Then Done
  344.  
  345.     Date_to_YMD
  346.     If xerr = 1 Then xerr = 0: Start_DoW
  347.  
  348.     Zellers
  349.  
  350.     Day_Names_Long
  351.  
  352.     YMD_to_Str
  353.  
  354.     Print: Print
  355.     Print " "; Dt$; " was/is/will be a "; WkDa$
  356.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  357.     Again: Start_DoW
  358.  
  359. Sub Start_DoWR
  360.     Cls
  361.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  362.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Day of Week Repetitive  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  363.     Print
  364.     Print " Enter date to start checking at (yyyy-mm-dd)";: Input Dt$
  365.     If LCase$(Dt$) = "q" Then Done
  366.  
  367.     Date_to_YMD
  368.     If xerr = 1 Then xerr = 0: Start_DoWR
  369.  
  370.     Print
  371.     Print " Do you want to check until today or for a given number of years?"
  372.     Input " Press 0 for today or a (positive) number up to 250 "; YrCt$
  373.     If LCase$(YrCt$) = "q" Then Done
  374.     YrCt = Val(YrCt$)
  375.  
  376.     If YrCt < 1 Then
  377.         YrCt = Val(Right$(Date$, 4)) - y
  378.     ElseIf YrCt > 250 Then
  379.         YrCt = 250
  380.     End If
  381.  
  382.     Zellers
  383.     b = dow
  384.  
  385.     Print
  386.     Print " Date             Day YrNo Count"
  387.     Print
  388.     row = 10
  389.     col = 23
  390.     x = 0
  391.     C = 0
  392.     Do Until x = YrCt
  393.         Zellers
  394.  
  395.         Day_Names_Short
  396.  
  397.         c$ = Str$(C)
  398.         x$ = Str$(x)
  399.  
  400.         If b = dow Then
  401.             y$ = Str$(y)
  402.             If m < 10 Then
  403.                 m$ = "0" + LTrim$(Str$(m))
  404.             Else
  405.                 m$ = Str$(m)
  406.             End If
  407.             If d < 10 Then
  408.                 d$ = "0" + LTrim$(Str$(d))
  409.             Else
  410.                 d$ = Str$(d)
  411.             End If
  412.  
  413.             Locate row, 1: Print " "; LTrim$(y$); "-"; LTrim$(m$); "-"; LTrim$(d$); "  was  "; WkDa$
  414.  
  415.             If x < 10 Then
  416.                 Locate row, col + 2: Print x$
  417.             ElseIf x < 100 Then
  418.                 Locate row, col + 1: Print x$
  419.             Else
  420.                 Locate row, col: Print x$
  421.             End If
  422.  
  423.             If C < 10 Then
  424.                 Locate row, col + 7: Print c$
  425.             ElseIf C < 100 Then
  426.                 Locate row, col + 6: Print c$
  427.             Else
  428.                 Locate row, col + 5: Print c$
  429.             End If
  430.             C = C + 1
  431.             row = row + 1
  432.         End If
  433.  
  434.         x = x + 1
  435.         y = y + 1
  436.     Loop
  437.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  438.     Again: Start_DoWR
  439.  
  440. Sub Start_DoY
  441.     Cls
  442.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  443.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Day of Year  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  444.     Print
  445.     Input " Enter a date, e.g. 1969-07-20 (yyyy-mm-dd): "; Dt$
  446.     If LCase$(Dt$) = "q" Then Done
  447.  
  448.     Date_to_YMD
  449.     If xerr = 1 Then xerr = 0: Start_DoY
  450.  
  451.     Day_Of_Year
  452.  
  453.     YMD_to_Str
  454.  
  455.     Print: Print
  456.     Print " "; Dt$; " was/is/will be day number "; doy
  457.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  458.     Again: Start_DoY
  459.  
  460. Sub Start_RDoY
  461.     Cls
  462.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  463.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Reverse Day of Year  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  464.     Print
  465.     Input " Enter year and day number, 1969-074 (yyyy-nnn): "; Dt$
  466.     If LCase$(Dt$) = "q" Then Done
  467.  
  468.     If Len(Dt$) <> 8 Then
  469.         Print " You need a 4 digit year '-' 3 digit day number: yyyy-nnn."
  470.         Input " Press 'Enter' to continue. ", q$
  471.         If LCase$(q$) = "q" Then Done
  472.         Start_RDoY
  473.     End If
  474.  
  475.     y = Val(Left$(Dt$, 4))
  476.     If y < 1583 Or y > 3266 Then
  477.         Print
  478.         Print " Enter a year between 1583 and 3266."
  479.         Input " Press 'Enter' to continue. ", q$
  480.         If LCase$(q$) = "q" Then Done
  481.         Start_RDoY
  482.     End If
  483.  
  484.     doy = Val(Right$(Dt$, Len(Dt$) - InStr(Dt$, "-")))
  485.  
  486.     Leap_Year
  487.     If LY = 0 Then
  488.         diy = 365
  489.     Else
  490.         diy = 366
  491.     End If
  492.  
  493.     If doy < 1 Or doy > diy Then
  494.         Print " You need day of year number between 1 and "; diy
  495.         Input " Press 'Enter' to continue. ", q$
  496.         If LCase$(q$) = "q" Then Done
  497.         Start_RDoY
  498.     End If
  499.  
  500.     If doy > 59 + LY Then
  501.         d = doy + 2 - LY
  502.     Else
  503.         d = doy
  504.     End If
  505.  
  506.     m = 100 * (d + 91) \ 3055
  507.     d = d + 91 - (3055 * m \ 100)
  508.     m = m - 2
  509.  
  510.     Zellers
  511.  
  512.     Day_Names_Long
  513.  
  514.     Month_Names_Long
  515.  
  516.     YMD_to_Str
  517.  
  518.     Print: Print
  519.     Print " For day number"; doy; "of"; y$; " the date was/is/will be "; WkDa$; ", "; MoNa$; d$
  520.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  521.     Again: Start_RDoY
  522.  
  523. Sub Start_DYMD
  524.     Cls
  525.     Print "ÉÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍ»"
  526.     Print "ÈÍÍÍÍÍÍÍÍÍͼ  Difference Between Dates in Years, Months, and Days  ÈÍÍÍÍÍÍÍÍÍÍͼ"
  527.     Print
  528.  
  529.     Input " Enter first date (yyyy-mm-dd)"; Dt$
  530.     If LCase$(Dt$) = "q" Then Done
  531.  
  532.     Date_to_YMD
  533.     If xerr = 1 Then xerr = 0: Start_DYMD
  534.  
  535.     Yr1 = y
  536.     Mo1 = m
  537.     Da1 = d
  538.     Dt1$ = Dt$
  539.  
  540.     Date_to_JD
  541.     JD1 = JD
  542.  
  543.     Input " Enter second date (yyyy-mm-dd)"; Dt$
  544.     If LCase$(Dt$) = "q" Then Done
  545.  
  546.     Date_to_YMD
  547.     If xerr = 1 Then xerr = 0: Start_DYMD
  548.  
  549.     Yr2 = y
  550.     mo2 = m
  551.     da2 = d
  552.     Dt2$ = Dt$
  553.  
  554.     Date_to_JD
  555.     JD2 = JD
  556.  
  557.     ' Determine which Date/JD is larger.
  558.     If JD1 > JD2 Then
  559.         LrJD = JD1
  560.         LrYr = Yr1
  561.         LrMo = Mo1
  562.         LrDa = Da1
  563.         LrDt$ = Dt1$
  564.         SmJD = JD2
  565.         SmYr = Yr2
  566.         SmMo = mo2
  567.         SmDa = da2
  568.         SmDt$ = Dt2$
  569.     Else
  570.         LrJD = JD2
  571.         LrYr = Yr2
  572.         LrMo = mo2
  573.         LrDa = da2
  574.         LrDt$ = Dt2$
  575.         SmJD = JD1
  576.         SmYr = Yr1
  577.         SmMo = Mo1
  578.         SmDa = Da1
  579.         SmDt$ = Dt1$
  580.     End If
  581.  
  582.     ' Find the difference between the two dates in days.
  583.     OpJ$ = Str$(LrJD - SmJD)
  584.     OpJD = LrJD - SmJD
  585.  
  586.     ' Find the Days, Months, and Years between the two dates.
  587.     ' Find Days
  588.     If SmDa = LrDa Then
  589.         OpDa = 0
  590.     ElseIf SmDa < LrDa Then
  591.         OpDa = LrDa - SmDa
  592.     Else
  593.         DM = LrMo
  594.         y = LrYr
  595.         Days_In_Month
  596.         OpDa = LrDa + dlm - SmDa
  597.         LrMo = LrMo - 1
  598.     End If
  599.  
  600.     'find Months
  601.     If SmMo = LrMo Then
  602.         OpMo = 0
  603.     ElseIf SmMo < LrMo Then
  604.         OpMo = LrMo - SmMo
  605.     Else
  606.         OpMo = LrMo + 12 - SmMo
  607.         LrYr = LrYr - 1
  608.     End If
  609.  
  610.     'find Years
  611.     If LrYr = SmYr Then
  612.         OpYr = 0
  613.     Else
  614.         OpYr = LrYr - SmYr
  615.     End If
  616.  
  617.     SJD$ = Str$(SmJD)
  618.     LJD$ = Str$(LrJD)
  619.  
  620.     Print: Print
  621.     Print " The difference between "; SmDt$; " and "; LrDt$; " is:"
  622.     Print
  623.     Print " "; LTrim$(OpJ$); " Days,"
  624.     Print " or"; OpYr; "Years,"; OpMo; "Months, and"; OpDa; "Days,"
  625.     Print " or"; OpYr * 12 + OpMo; "Months and"; OpDa; "Days,"
  626.     Print " or"; OpJD \ 7; "Weeks and"; OpJD Mod 7; "Days."
  627.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  628.     Again: Start_DYMD
  629.  
  630. Sub Start_Easter
  631.     Cls
  632.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  633.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Find Easter  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  634.     Print
  635.     Input " Enter a year yyyy: ", y$
  636.     If LCase$(y$) = "q" Then Done
  637.     y = Val(y$)
  638.  
  639.     If Len(y) <> 4 Or y < 1583 Or y > 3266 Then
  640.         Print
  641.         Print " Enter a year between 1583 and 3266."
  642.         Input " Press 'Enter' to continue. ", q$
  643.         If LCase$(q$) = "q" Then Done
  644.         Start_RDoY
  645.     End If
  646.  
  647.     A = y Mod 19
  648.     B = y Mod 4
  649.     C = y Mod 7
  650.     P = (y \ 100)
  651.     Q = ((13 + 8 * P) \ 25)
  652.     m = (15 - Q + P - P \ 4) Mod 30
  653.     n = (4 + P - P \ 4) Mod 7
  654.     d = (19 * A + m) Mod 30
  655.     E = (2 * B + 4 * C + 6 * d + n) Mod 7
  656.     day = (22 + d + E)
  657.  
  658.     If d = 29 And E = 6 Then
  659.         m = 4
  660.         d = 19
  661.     ElseIf d = 28 And E = 6 Then
  662.         m = 4
  663.         d = 18
  664.     Else
  665.         If day > 31 Then
  666.             day$ = Str$(day - 31)
  667.             If Val(day$) < 10 Then day$ = Str$(0) + LTrim$(day$)
  668.             m = 4
  669.             d = day - 31
  670.         Else
  671.             day$ = Str$(day)
  672.             If Val(day$) < 10 Then day$ = Str$(0) + LTrim$(day$)
  673.             m = 3
  674.             d = day
  675.         End If
  676.     End If
  677.  
  678.     Month_Names_Long
  679.     Print: Print
  680.     Print " In"; y; "Easter was/is/will be on Sunday, "; MoNa$; day$
  681.  
  682.     Date_to_JD
  683.     JD = JD - 47
  684.  
  685.     JD_to_Date
  686.  
  687.     YMD_to_Str
  688.  
  689.     Month_Names_Long
  690.  
  691.     Print " And Mardi Gras was/is/will be on Tuesday, "; MoNa$; d$
  692.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  693.     Again: Start_Easter
  694.  
  695. Sub Start_Date_to_JD
  696.     Cls
  697.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  698.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Date to Julian Day Number  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  699.     Print
  700.     Input " Enter a date yyyy-mm-dd: ", Dt$
  701.     If LCase$(Dt$) = "q" Then Done
  702.  
  703.     Date_to_YMD
  704.     If xerr = 1 Then xerr = 0: Start_Date_to_JD
  705.  
  706.     Date_to_JD
  707.  
  708.     Print: Print
  709.     Print " "; LTrim$(Dt$); " is Julian Day number: "; JD
  710.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  711.     Again: Start_Date_to_JD
  712.  
  713. Sub Start_JD_to_Date
  714.     Cls
  715.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  716.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Julian Day Number to Date  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  717.     Print
  718.     Input " Enter a number between 2299239 (1583-01-01) and 2914307 (3266-12-31): ", JD$
  719.     If LCase$(JD$) = "q" Then Done
  720.     JD = Val(JD$)
  721.  
  722.     If JD < 2299239 Or JD > 2914672 Then
  723.         Print " You entered "; JD$; " This is an incorrect value for the JD number."
  724.         Input " Press 'Enter' to continue. ", q$
  725.         If LCase$(q$) = "q" Then Done
  726.         Start_JD_to_Date
  727.     End If
  728.  
  729.     JD_to_Date
  730.  
  731.     Zellers
  732.  
  733.     Day_Names_Long
  734.  
  735.     YMD_to_Str
  736.  
  737.     Print: Print
  738.     Print " "; JD$; " is the Julian Day Number for "; WkDa$ + y$ + "-" + LTrim$(m$) + "-" + LTrim$(d$)
  739.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  740.     Again: Start_JD_to_Date
  741.  
  742. Sub Start_Leap_Year
  743.     Cls
  744.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  745.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Leap Year  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  746.     Print
  747.     Input " Enter a year yyyy: ", y$
  748.     If LCase$(y$) = "q" Then Done
  749.     y = Val(y$)
  750.     If y < 1583 Or y > 3266 Then
  751.         Print
  752.         Print " Enter a year between 1583 and 3266."
  753.         Input " Press 'Enter' to continue. ", q$
  754.         If LCase$(q$) = "q" Then Done
  755.         Start_Leap_Year
  756.     End If
  757.  
  758.     Leap_Year
  759.     If LY = 1 Then
  760.         ly$ = "Yes"
  761.         lyw$ = "was/is/will be"
  762.     Else
  763.         ly$ = "No"
  764.         lyw$ = "wasn't/isn't/won't be"
  765.     End If
  766.     Print: Print
  767.     Print " "; ly$; " "; y$; " "; lyw$; " a Leap Year."
  768.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  769.     Again: Start_Leap_Year
  770.  
  771. Sub Start_WkNo
  772.     Cls
  773.     Print "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  774.     Print "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  Week Number  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  775.     Print
  776.     Input " Enter a date yyyy-mm-dd: ", Dt$
  777.     If LCase$(Dt$) = "q" Then Done
  778.     Date_to_YMD
  779.     If xerr = 1 Then xerr = 0: Start_WkNo
  780.  
  781.     lwn = (y + (y \ 4) - (y \ 100) + (y \ 400)) Mod 7
  782.  
  783.     Zellers
  784.     If dow = 0 Then dow = 7
  785.  
  786.     Day_Of_Year
  787.  
  788.     WN = (10 + doy - dow) \ 7
  789.  
  790.     If WN < 1 Then
  791.         yy = y: y = y - 1
  792.         mm = m: m = 1
  793.         dd = d: d = 1
  794.         Zellers
  795.         Leap_Year
  796.         If dow = 4 Then
  797.             WN = 53
  798.         ElseIf dow = 3 And LY = 1 Then
  799.             WN = 53
  800.         Else
  801.             WN = 52
  802.         End If
  803.         y = yy: m = mm: d = dd
  804.         Zellers
  805.         If dow = 7 Then dow = 0
  806.         Day_Names_Long
  807.         If m = 1 And WN > 50 Then y = y - 1
  808.         WN$ = Str$(WN)
  809.         Print: Print
  810.         Print " "; Dt$; " is "; WkDa$; " of week number"; RTrim$(WN$); ","; y
  811.     Else
  812.         Zellers
  813.         If dow = 7 Then dow = 0
  814.         Day_Names_Long
  815.         If lwn < 4 And WN = 53 Then
  816.             WN = 1
  817.             y = y + 1
  818.         End If
  819.         WN$ = Str$(WN)
  820.         Print: Print
  821.         Print " "; Dt$; " is "; WkDa$; " of week number"; RTrim$(WN$); ","; y
  822.     End If
  823.  
  824.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  825.     Again: Start_WkNo
  826.  
  827. ' ================================================================================
  828. '                        common SUBs used by other routines
  829. ' ================================================================================
  830.  
  831. Sub Again
  832.     Dt$ = ""
  833.     y = 0
  834.     m = 0
  835.     d = 0
  836.     JD = 0
  837.     row = CsrLin
  838.     Do
  839.         Locate row, 1: Print "                                                                               "
  840.         Locate row, 1: Input " Enter 'A' to go again, 'M' for main menu, or 'Q' to quit (A/M/Q)"; q$
  841.         q$ = LCase$(q$)
  842.         If q$ = "a" Then
  843.             Exit Do
  844.         ElseIf q$ = "m" Then
  845.             Main_Menu
  846.         ElseIf q$ = "q" Then
  847.             Done
  848.         End If
  849.     Loop
  850.  
  851. ' Gives the day of week for any Gregorian calendar date.
  852. Sub Zellers
  853.     If m > 2 Then
  854.         mz = m - 2: yz = y
  855.     Else
  856.         mz = m + 10: yz = y - 1
  857.     End If
  858.  
  859.     cz = yz \ 100: dz = yz - 100 * cz
  860.     dow = ((13 * mz - 1) \ 5) + d + dz + (dz \ 4) + (cz \ 4) - cz - cz + 77
  861.     dow = dow - 7 * (dow \ 7)
  862.  
  863. ' Gives the day of the year
  864. Sub Day_Of_Year
  865.     doy = (3055 * (m + 2) \ 100) - 91
  866.     Leap_Year
  867.     If m > 2 Then doy = doy - 2 + LY
  868.     doy = doy + d
  869.  
  870. Sub Leap_Year
  871.     LY = 0
  872.     If y Mod 4 = 0 Then LY = 1
  873.     If y Mod 100 = 0 Then LY = 0
  874.     If y Mod 400 = 0 Then LY = 1
  875.  
  876. ' Get the number of days for last month (dlm), this month (dtm), and next month (dnm)
  877. Sub Days_In_Month
  878.     Leap_Year
  879.     DM1 = DM * 2 - 1
  880.     dlm = Val(Mid$("313128313031303131303130", DM1, 2))
  881.     If dlm = 28 And LY = 1 Then dlm = 29
  882.     dtm = Val(Mid$("312831303130313130313031", DM1, 2))
  883.     If dtm = 28 And LY = 1 Then dtm = 29
  884.     dnm = Val(Mid$("283130313031313031303131", DM1, 2))
  885.     If dnm = 28 And LY = 1 Then dnm = 29
  886.  
  887. ' Convert a Gregorian Date to a Julian Day number.
  888. Sub Date_to_JD
  889.     JD = d - 32075 + (1461 * (y + 4800 + ((m - 14) \ 12)) \ 4) + 367 * (m - 2 - ((m - 14) \ 12) * 12) \ 12 - 3 * ((y + 4900 + ((m - 14) \ 12)) \ 100) \ 4
  890.  
  891. ' Convert a Julian Day number to a Gregorian Date.
  892. Sub JD_to_Date
  893.     L = JD + 68569
  894.     n = 4 * L \ 146097
  895.     L = L - (146097 * n + 3) \ 4
  896.     y = 4000 * (L + 1) \ 1461001
  897.     L = L - (1461 * y \ 4) + 31
  898.     m = 80 * L \ 2447
  899.     d = L - (2447 * m \ 80)
  900.     L = m \ 11
  901.     m = m + 2 - (12 * L)
  902.     y = 100 * (n - 49) + y + L
  903.  
  904. Sub Day_Names_Short
  905.     Select Case dow
  906.         Case 0: WkDa$ = "Sun"
  907.         Case 1: WkDa$ = "Mon"
  908.         Case 2: WkDa$ = "Tue"
  909.         Case 3: WkDa$ = "Wed"
  910.         Case 4: WkDa$ = "Thu"
  911.         Case 5: WkDa$ = "Fri"
  912.         Case 6: WkDa$ = "Sat"
  913.     End Select
  914.  
  915. Sub Day_Names_Long
  916.     Select Case dow
  917.         Case 0: WkDa$ = "Sunday"
  918.         Case 1: WkDa$ = "Monday"
  919.         Case 2: WkDa$ = "Tuesday"
  920.         Case 3: WkDa$ = "Wednesday"
  921.         Case 4: WkDa$ = "Thursday"
  922.         Case 5: WkDa$ = "Friday"
  923.         Case 6: WkDa$ = "Saturday"
  924.     End Select
  925.  
  926. Sub Month_Names_Short
  927.     Select Case m
  928.         Case 1: MoNa$ = "Jan"
  929.         Case 2: MoNa$ = "Feb"
  930.         Case 3: MoNa$ = "Mar"
  931.         Case 4: MoNa$ = "Apr"
  932.         Case 5: MoNa$ = "May"
  933.         Case 6: MoNa$ = "Jun"
  934.         Case 7: MoNa$ = "Jul"
  935.         Case 8: MoNa$ = "Aug"
  936.         Case 9: MoNa$ = "Sep"
  937.         Case 10: MoNa$ = "Oct"
  938.         Case 11: MoNa$ = "Nov"
  939.         Case 12: MoNa$ = "Dec"
  940.     End Select
  941.  
  942. Sub Month_Names_Long
  943.     Select Case m
  944.         Case 1: MoNa$ = "January"
  945.         Case 2: MoNa$ = "February"
  946.         Case 3: MoNa$ = "March"
  947.         Case 4: MoNa$ = "April"
  948.         Case 5: MoNa$ = "May"
  949.         Case 6: MoNa$ = "June"
  950.         Case 7: MoNa$ = "July"
  951.         Case 8: MoNa$ = "August"
  952.         Case 9: MoNa$ = "September"
  953.         Case 10: MoNa$ = "October"
  954.         Case 11: MoNa$ = "November"
  955.         Case 12: MoNa$ = "December"
  956.     End Select
  957.  
  958. ' Convert input date (Dt$) to year, month, and day integers And check that they are valid
  959. Sub Date_to_YMD
  960.     y = Val(Left$(Dt$, 4))
  961.     m = Val(Mid$(Dt$, 6, 2))
  962.     d = Val(Right$(Dt$, 2))
  963.  
  964.     DM = m
  965.     Days_In_Month
  966.     If Len(Dt$) <> 10 Then
  967.         Print
  968.         Print " Your date has too few or too many characters in it."
  969.         Input " Press 'Enter' to continue. ", q$
  970.         If LCase$(q$) = "q" Then Done
  971.         xerr = 1
  972.     ElseIf y < 1583 Or y > 3266 Then
  973.         Print
  974.         Print " Enter a year between 1583 and 3266."
  975.         Input " Press 'Enter' to continue. ", q$
  976.         If LCase$(q$) = "q" Then Done
  977.         xerr = 1
  978.     ElseIf m < 1 Or m > 12 Then
  979.         Print
  980.         Print " Enter a month number between 1 and 12."
  981.         Input " Press 'Enter' to continue. ", q$
  982.         If LCase$(q$) = "q" Then Done
  983.         xerr = 1
  984.     ElseIf d < 1 Or d > dtm Then
  985.         Print
  986.         Print " Enter a day number between 1 and "; dtm;
  987.         Input " Press 'Enter' to continue. ", q$
  988.         If LCase$(q$) = "q" Then Done
  989.         xerr = 1
  990.     End If
  991.  
  992. ' Convert Year, month, and day integers to strings and add leading 0s to digits less than 10
  993. Sub YMD_to_Str
  994.     y$ = Str$(y)
  995.     m$ = Str$(m)
  996.     d$ = Str$(d)
  997.  
  998.     If m < 10 Then m$ = Str$(0) + LTrim$(m$)
  999.     If d < 10 Then d$ = Str$(0) + LTrim$(d$)
  1000.  
  1001. Sub Why_Dates
  1002.     Cls
  1003.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  1004.     Print
  1005.     Print "    CalenTools will not work with years prior to 1583 or after 3266, this was"
  1006.     Print " done intentionally partly as an error prevention measure."
  1007.     Print "    Prior to 1583 most of the western world used the Julian Calendar which had"
  1008.     Print " an extra 3 leap years every 400 years.  Pope Gregory XIII wrote a papal bull"
  1009.     Print " in Feb. 1582 to correct for this error by suppressing 10 days.  Thus causing"
  1010.     Print " Oct. 5, 1582 to become Oct. 15, 1582.  (So I dropped the last two and a half"
  1011.     Print " months of 1582 because and I don't think most people will need them)."
  1012.     Print "    The papel bull was adopted by most countries at different times.  A lof of"
  1013.     Print " Roman Catholic countries Spain, Portugal, etc. and their colonies changed on"
  1014.     Print " Oct. 15, 1582. Great Britain and the American colonies changed in 1752.  The"
  1015.     Print " most recant change from The Julian calendar that I know of is Turkey in 1927."
  1016.     Print "    As Far as I know only a few religions still use the Julian calendar.  You"
  1017.     Print " can use the search engine of your choice to find a list of when the different"
  1018.     Print " countries adopted the Gregorian calendar."
  1019.     Print "    As for after 3266, it my be my limited sense of reality, but I don't really"
  1020.     Print " think it's necessary as I think there will be something better by then.  Maybe"
  1021.     Print " even a whole new calendar system. "
  1022.     Print "    Also it's the end of the first Julian Period so Julian Day numbers will"
  1023.     Print " restart at one.  I'm using Julian Day numbers are here to 'Add or Subtract"
  1024.     Print " Days' and to find the 'Difference between two dates'."
  1025.     Print "    The Julian Period and Julian Day numbers (not to be confused with the"
  1026.     Print " Julian Calendar) start at noon on -4712-01-01 of the Julian calendar (or"
  1027.     Print " -4713-11-24 Gregorian Calendar).  This is because in 4713 BC the 'Indiction'"
  1028.     Print " (15 yrs.), the 'Golden Number' (19) and the 'Solar Number' (28 yrs.) were all"
  1029.     Print " one.  The Julian Period is 7980 years long.  The next time this happens is"
  1030.     Print " Jan. 01, 3268 Julian calendar or Nov. 24, 3267 Gregorian calendar."
  1031.     Print "ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"
  1032.     Print
  1033.     Print "    The ISO (International Organization for Standardization) week starts on"
  1034.     Print " Mon. The 1st week of the year has Jan. 4th and the first Thu. of the year in"
  1035.     Print " it. If Jan. the 1st is a Thu., making Sun. the 4th the last day of the week,"
  1036.     Print " the first day of the first week is Mon. Dec. 29th of the previous year.  If"
  1037.     Print " Jan. 4th is a Mon. then Jan. 1st is Fri. of the last week of the previous year."
  1038.     Print "    Also a year that starts on Thu. (or Wed. if a leap year) has 53 weeks"
  1039.     Print " because there are 53 Thu. in the year and therefore 53 continuous weeks that"
  1040.     Print " each have at least 4 days of the current calendar year per week.  Therefore,"
  1041.     Print " Fri. Jan. 1st 2016 is Fri. of the 53rd week of 2015."
  1042.     Print "    There are 71 of these 53 week years every 400 years."
  1043.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  1044.     Input " Press 'Enter' to continue. ", q$
  1045.     If LCase$(q$) = "q" Then
  1046.         Done
  1047.     Else
  1048.         Main_Menu
  1049.     End If
  1050.  
  1051. Sub Save_1st_Day
  1052.     Cls
  1053.     Print
  1054.     Print "ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ"
  1055.     Print " Saving this will create a 3 byte file on your hard drive.  This file will"
  1056.     Print " waste a lot of space.  Depending on drive size and operating system you are"
  1057.     Print " wasting, on average, between 509 to 4093 bytes.  Just to save you from having"
  1058.     Print " to press 's' or 'm' every time you view calendars in CalenTools."
  1059.     Print
  1060.     Print " The file it creates will be in the same directory that you have CalenTools in."
  1061.     Print " So if you have it on the desktop you will end up with two CalenTools files on"
  1062.     Print " your desktop.   Also if for whatever reason you happen to have a file named"
  1063.     Print " 'calentools.dat' in the same directory it will be over written."
  1064.     Print
  1065.     Input " Do you wish to continue (Y/N)"; q$
  1066.     q$ = LCase$(q$)
  1067.     If q$ = "q" Then
  1068.         Done
  1069.     ElseIf q$ = "n" Then
  1070.         Cals
  1071.     ElseIf q$ = "y" Then
  1072.         Do_Save
  1073.     Else
  1074.         Save_1st_Day
  1075.     End If
  1076.  
  1077. Sub Do_Save
  1078.     fd$ = FDay$ 'This is in case you are using Sun. but want to save Mon.
  1079.     Print
  1080.     Input " Do you want the week to start on Sunday or Monday (S/M)"; q$
  1081.     q$ = LCase$(q$)
  1082.     If q$ = "q" Then Done
  1083.     FDay$ = q$
  1084.     filenum = FreeFile
  1085.     Open "calentools.dat" For Output As #filenum
  1086.     Print #filenum, FDay$
  1087.     Close #filenum
  1088.     FDay$ = fd$
  1089.     Cals
  1090.  
  1091. Sub Done
  1092.     System
  1093.