Microsoft Small Basic

Program Listing: FMQ297
' CAL - Calender
' (c) 1986, 2010 N.Takahashi
dom[1] = 31
dom[2] = 28
dom[3] = 31
dom[4] = 30
dom[5] = 31
dom[6] = 30
dom[7] = 31
dom[8] = 31
dom[9] = 30
dom[10] = 31
dom[11] = 30
dom[12] = 31
restart:
TextWindow.Write("Year,month? ")
inputline=TextWindow.Read()
ParseArgs()
year = arg[1]
if year = "" Then
Goto end
Endif
If year < 1 Then
Goto restart
Endif
If Math.Remainder(year, 4) = 0 And Math.Remainder(year, 100) > 0 Or Math.Remainder(year, 400) = 0 Then
dom[2] = dom[2] + 1
Endif
nol = Math.Floor((year - 1) / 4) - Math.Floor((year - 1) / 100) + Math.Floor((year - 1) / 400)
woy = Math.Remainder((year + nol), 7)
month = arg[2]
If month = "" Then
m0 = 1
m1 = 12
Else
If month < 1 Or month > 12 Then
Goto restart
EndIf
m0 = month
m1 = month
Endif
'
doy = 0
im = 1
For m = m0 To m1
While im < m
doy = doy + dom[im]
im = im + 1
EndWhile
w = Math.Remainder((doy + woy), 7)
TextWindow.Write(" ")
If year < 10 Then
TextWindow.Write(" " + year)
ElseIf year < 100 Then
TextWindow.Write(" " + year)
ElseIf year < 1000 Then
TextWindow.Write(" " + year)
Else
TextWindow.Write(year)
EndIf
TextWindow.Write(" ")
If m < 10 Then
TextWindow.WriteLine(" " + m)
Else
TextWindow.WriteLine(m)
EndIf
TextWindow.WriteLine("")
TextWindow.WriteLine("SUN MON TUE WED THU FRI SAT")
wom = 0
While wom < w
TextWindow.Write(" ")
wom = wom + 1
EndWhile
For i = 1 To dom[m]
If i < 10 Then
TextWindow.Write(" " + i + " ")
Else
TextWindow.Write(" " + i + " ")
EndIf
If Math.Remainder(wom, 7) = 6 Then
TextWindow.WriteLine("")
EndIf
wom = wom + 1
EndFor
If Math.Remainder(wom, 7) > 0 Then
TextWindow.WriteLine("")
EndIf
TextWindow.WriteLine("")
EndFor
end:
'Program.End()
Sub ParseArgs
p = 1
n = 1
c = Text.GetIndexOf(inputline, ",")
While c > p
arg[n] = Text.GetSubText(inputline, p, c - p)
p = c + 1
n = n + 1
comma = Text.GetIndexOf(inputline, ",")
EndWhile
e = Text.GetLength(inputline) + 1
arg[n] = Text.GetSubText(inputline, p, e - p)
EndSub
'
' reference
' 1) H.SASAKI: IBM-JX 1st. step ペーパーソフトの楽しみ方 (学研, 1985)