An example of a calendar written in Run BASIC.

' Calendar example
' By Neal Collins, Jan 2008

' Default month is the current month
month=val(date$("mm"))
year=val(date$("yyyy"))
 
' Setup an array of month names
dim monthName$(11)
monthName$(0) = "January"
monthName$(1) = "February"
monthName$(2) = "March"
monthName$(3) = "April"
monthName$(4) = "May"
monthName$(5) = "June"
monthName$(6) = "July"
monthName$(7) = "August"
monthName$(8) = "September"
monthName$(9) = "October"
monthName$(10) = "November"
monthName$(11) = "December"
 
' Fill the years array with the 10 years prior to the current year
dim years$(10)
for i = 0 to 10
years$(i) = str$(year - i)
next
 
[display]
cls
 
html "<h1>Calendar Example</h1>"
print "An example of a calendar written in Run BASIC."
print
 
' We need a database connection so we can use the sqlite date functions
sqliteconnect #db, "dummy.db"
 
' Make the date string 'yyyy-mm-01'
d$ = str$(year) + "-"
if month < 10 then d$ = d$ + "0" ' Month must be padded to 2 digits
d$ = d$ + str$(month) + "-01"
 
' Get the day of the week of the 1st day in the month
query$ = "select strftime('%w', '" + d$ + "')"
#db execute(query$)
day = val(#db nextrow$(","))
 
' Get the last day of the month
query$ = "select strftime('%d','" + d$ + "','start of month','+1 month','-1 day')"
#db execute(query$)
last = val(#db nextrow$(","))
 
#db disconnect()
 
caption$ = "Calendar for " + left$(monthName$(month - 1), 3) + " " + str$(year)
 
' Fill the calendar array
dim cal$(6, 4)
for i = 1 to last
d = i + day
col = (d - 1) mod 7
row = int((d - 1) / 7)
if row = 5 then row = 0
cal$(col, row) = str$(i)
next
 
' Display next, previous month and year links
link #prevYear, "<<", [prevYear]
print " ";
link #prevMonth, "<", [prevMonth]
print " ";
link #nextMonth, ">", [nextMonth]
print " ";
link #nextYear, ">>", [nextYear]
print
 
' Display the calendar
table #calendar, cal$()
#calendar columnnames("Sun,Mon,Tue,Wed,Thu,Fri,Sat")
#calendar caption(caption$)
#calendar link("Sun", "[select]")
#calendar link("Mon", "[select]")
#calendar link("Tue", "[select]")
#calendar link("Wed", "[select]")
#calendar link("Thu", "[select]")
#calendar link("Fri", "[select]")
#calendar link("Sat", "[select]")
 
render #calendar
 
' Display month and year selection box
print
listbox #month, monthName$(), 1
print " ";
listbox #year, years$(), 1
print " ";
link #selMonth, "Go", [selMonth]
print
 
wait
 
[selMonth]
' Update the month and year to those selected
m$ = #month selection$()
for i = 0 to 11
if m$ = monthName$(i) then
month = i + 1
exit for
end if
next
year = val(#year selection$())
goto [display]
 
[prevMonth]
' Go to the previous month
month = month - 1
if month < 1 then
month = 12
year = year - 1
end if
goto [display]
 
[nextMonth]
' Go to the next month
month = month + 1
if month > 12 then
month = 1
year = year + 1
end if
goto [display]
 
[prevYear]
' Go to the previous year
year = year - 1
goto [display]
 
[nextYear]
' Go to the next year
year = year + 1
goto [display]
 
[select]
' A date was clicked on
print "You clicked on "; EventKey$; " "; monthName$(month - 1); " "; year
wait