There is some help info in the code. If you need more help or have a suggestion please post it. I moved the text editing page to a function, which can be easily lifted and used in your programs with a little changing.
I adapted ricardobytes method to make the app work on all iOS devices. Thanks, ricardobytes!
- Dav
New for v1.2: Added option to make entry highlighted red to mark as important.
Code: Select all
'================
'GigBook.txt v1.2
'================
'An event calendar/journal
'Works on ipad/iphone/ipod touch
'ONLY GOOD FOR YEARS BETWEEN 2016-2033
'Coded by Dav, OCT/2016
'
'NEW for v1.2: Added red highlight entry.
'
'HOW TO USE:
'^^^^^^^^^^
'This app lets you save important dates.
'You can also save memos and phone numbers.
'Use arrows to navigate the month to view.
'Or use Year & Month buttons to jump there.
'Press a number to add events on that day.
'An editing window will open to allow input.
'Press Done when you have finished editing.
'Pressing Clear will erase/delete the entry.
'Highlighted days mean an event is scheduled.
'To mark to entry as important and have it
'displayed red in the monthly view, just put
'an exclamation mark at top left in entry.
'To erase highlight press Clear when editing.
'Data saved in the /gigbook-data/ directory.
'Entry filenames saved like: 2016-10-12.txt
'CREDITS: I used ricardobytes method to make
'the app compatible with both ipad & iphone.
option base 1
set orientation vertical
get screen size sw,sh
'detect device for screen settings
if lowstr$(device_type$())="ipad" then
rw=1!rh=1!vmod=0
else
rw=sw/768!rh=sh/1024!vmod=50
end if
'========= for testing purposes ============
'call iphone("4") '<<<< force test iphone 4
'call iphone("5") '<<<< force test iphone 5
'call iphone("6") '<<<< force test iphone 6
'call iphone("6+")'<<<< force test iphone 6+
'===========================================
'make gigbook directory if doesn't exist
if file_exists("gigbook-data/") = 0 then
dir "gigbook-data" create
end if
'===
top:
'===
graphics
graphics clear .9,.9,.9
set buttons custom
set buttons font size 42*rw
gosub GetData
draw color 0,0,.8
fill color .9,.9,1
draw font size 56*rw
centertext(month$&" - "&str$(SelYear),30)
draw font size 37*rw
draw text "Sun Mon Tue Wed Thu Fri Sat" at 10*rw,100*rh
'draw a month view
y=150*rh!yc=sw/7!dim day$(days)!events=0
for t = 1 to days
day$(t)=dayname$(xp)
draw color 0,0,.8
'see if event saved for this day
'if so, make button special color.
entry$=str$(SelYear)&"-"&str$(SelMonth)&"-"&str$(t)&".txt"
if file_exists("gigbook-data/"&entry$) =1 then
events=events+1
fill color .89,.89,1
'see if its marked important...
f$="gigbook-data/"&entry$
file f$ setpos 0 ! file f$ read m
'if so, make entry red filled.
if m=asc("!") then fill color 1,.89,.89
else
fill color 1,1,1
end if
'use special color if days todays date
if current_year()=SelYear then
if SelMonth=current_month() then
if t=current_date() then
draw color 1,1,1
fill color 0,0,1
end if
end if
end if
'draw days in the month
button str$(t) text t at yc*(xp-1),y size yc,yc
xp=xp+1
if xp=8 then
xp=1!y=y+yc
end if
next t
'draw nav buttons
set buttons font size 65*rw
button "<" text chr$(9664) at 25*rw,20*rh size 75*rw,75*rh
button ">" text chr$(9654) at sw-(91*rw),20*rh size 75*rw,75*rh
set buttons font size 42*rw
'draw info at bottom
draw font size 32*rw
'show todays date
centertext("Today is "&today$,900)
'see if today has and entry
te$=str$(SelYear)&"-"&str$(current_month())&"-"&str$(current_date())&".txt"
if file_exists("gigbook-data/"&te$) =1 then
centertext("An event is scheduled today",936)
else
centertext("No events scheduled today",936)
end if
'draw buttons at bottom
draw font size 37*rw
button "year" text "Year" at 40*rw,830*rh size 135*rw,56*rh
button "month" text "Month" at 200*rw,830*rh size 145*rw,56*rh
button "memo" text "Memo" at 375*rw,830*rh size 145*rw,56*rh
button "phone" text "Phone#" at 550*rw,830*rh size 175*rw,56*rh
'wait for user to make a move
do
for d=1 to days
if button_pressed(str$(d)) then
gosub erasebuttons
a$=day$(d)&" "&month$&" "
a$=a$&str$(d)&", "&str$(SelYear)
b$=str$(SelYear)&"-"&str$(SelMonth)
b$=b$&"-"&str$(d)&".txt"
EditText(a$,"gigbook-data/"&b$)
goto Top
end if
next d
if button_pressed("<") then
if SelMonth=1 and SelYear=2016 then
'dont do anything. hit wall.
else
gosub erasebuttons
'subtract month
SelMonth = SelMonth - 1
if SelMonth=0 then
SelMonth=12!SelYear=SelYear-1
end if
goto Top
end if
end if
if button_pressed(">") then
if SelMonth=12 and SelYear=MaxYear then
'dont do anything. hit wall.
else
gosub erasebuttons
SelMonth = SelMonth +1
if SelMonth=13 then
SelMonth=1!SelYear=SelYear+1
end if
goto Top
end if
end if
if button_pressed("year") then
gosub ShowYears ! goto top
end if
if button_pressed("month") then
gosub ShowMonths ! goto top
end if
if button_pressed("memo") then
gosub erasebuttons
a$="Memo: Save your notes & info"
EditText(a$,"gigbook-data/memo.txt")
goto top
end if
if button_pressed("phone") then
gosub erasebuttons
a$="Your Phone numbers & emails"
EditText(a$,"gigbook-data/phone.txt")
goto top
end if
slowdown
until 0
end
'=================================
' G O S U B S / F U N C T I O N S
'=================================
'=======
GetData: 'Gets & set Month & day data.
'======= 'xp is day of week the 1st on
MaxYear=2033 'data only up to this year.
'default selected year is current year
if SelYear=0 then SelYear=current_year()
'if out of date, go to last good year
if SelYear>MaxYear then SelYear=MaxYear
'default is current month
if SelMonth=0 then SelMonth=current_month()
'Data for years 2016-2033 is below.
'Contains number for each month - it's the
'day of week the 1st falls on. The last 2
'numbers is how many days FEB has for
'that year, 28 or 29. (FEB has leap years).
'There's a math formula to figure this out,
'but I dont have it in my head.
if SelYear=2016 then i$="62361462573529"
if SelYear=2017 then i$="14472573614628"
if SelYear=2018 then i$="25513614725728"
if SelYear=2019 then i$="36624725136128"
if SelYear=2020 then i$="47146247351329"
if SelYear=2021 then i$="62257351462428"
if SelYear=2022 then i$="73361462573528"
if SelYear=2023 then i$="14472573614628"
if selYear=2024 then i$="25624725136129"
if SelYear=2025 then i$="47735136247228"
if SelYear=2026 then i$="51146247351328"
if SelYear=2027 then i$="62257351462428"
if SelYear=2028 then i$="73472573614629"
if SelYear=2029 then i$="25513614725728"
if SelYear=2030 then i$="36624725136128"
if SelYear=2031 then i$="47735136247228"
if SelYear=2032 then i$="51257351462429"
if SelYear=2033 then i$="73361462573528"
if SelMonth = 1 then
month$="January" ! days = 31
xp = val(mid$(i$,1,1))
end if
if SelMonth = 2 then
month$="February"
days = val(mid$(i$,13,2))
xp = val(mid$(i$,2,1))
end if
if SelMonth = 3 then
month$="March" ! days = 31
xp = val(mid$(i$,3,1))
end if
if SelMonth = 4 then
month$="April" ! days = 30
xp = val(mid$(i$,4,1))
end if
if SelMonth = 5 then
month$="May" ! days = 31
xp = val(mid$(i$,5,1))
end if
if SelMonth = 6 then
month$="June" ! days = 30
xp = val(mid$(i$,6,1))
end if
if SelMonth = 7 then
month$="July" ! days = 31
xp = val(mid$(i$,7,1))
end if
if SelMonth = 8 then
month$="August" ! days = 31
xp = val(mid$(i$,8,1))
end if
if SelMonth = 9 then
month$="September" ! days = 30
xp = val(mid$(i$,9,1))
end if
if SelMonth = 10 then
month$="October" ! days = 31
xp = val(mid$(i$,10,1))
end if
if SelMonth = 11 then
month$="November" ! days = 30
xp = val(mid$(i$,11,1))
end if
if SelMonth = 12 then
month$="December" ! days = 31
xp = val(mid$(i$,12,1))
end if
return
'========
ShowYears:
'========
gosub erasebuttons
graphics clear .9,.9,.9
draw font size 56*rw
centertext("Select year:",30)
y=150*rh!yc=sw/6!xp=1
for t = 2016 to MaxYear
'draw years
button str$(t) text t at yc*(xp-1),y size yc,yc
xp=xp+1
if xp=7 then
xp=1!y=y+yc
end if
next t
do
for d=2016 to MaxYear
if button_pressed(str$(d)) then
SelYear=d
goto yeardone
end if
next d
until 0
yeardone:
for t = 2016 to MaxYear
button str$(t) delete
next t
return
'=========
ShowMonths:
'=========
gosub EraseButtons
dim m$(12)!m$(1)="January"!m$(2)="February"
m$(3)="March"!m$(4)="April"!m$(5)="May"
m$(6)="June"!m$(7)="July"!m$(8)="August"
m$(9)="September"!m$(10)="October"
m$(11)="November"!m$(12)="December"
graphics clear .9,.9,.9
draw font size 56*rw
centertext("Select month:",30)
y=150
for t = 1 to 12
'draw month
button str$(t) text m$(t) at 200*rw,y*rh size 400*rw,56*rh
y=y+60
next t
do
for d=1 to 12
if button_pressed(str$(d)) then
SelMonth=d
goto monthdone
end if
next d
until 0
monthdone:
for t = 1 to 12
button str$(t) delete
next t
return
'===========
EraseButtons:
'===========
button "<" delete ! button ">" delete
for t = 1 to days
button str$(t) delete
next t
button "year" delete
button "month" delete
button "memo" delete
button "phone" delete
return
'=================================
def iphone(dev$)
'settings for iphone/ipod devices
'iphone/ipod 4/5/6/6+
'default is iphone 6
.sw=375!.sh=667
if dev$="4" then
.sw=320!.sh=480
end if
if dev$="5" then
.sw=320!.sh=568
end if
if dev$="6" then
.sw=375!.sh=667
end if
if dev$="6+" then
.sw=414!.sh=736
end if
.rw=.sw/768!.rh=.sh/1024
end def
'=================================
def dayname$(num)
if num = 1 then return "Sunday"
if num = 2 then return "Monday"
if num = 3 then return "Tuesday"
if num = 4 then return "Wednesday"
if num = 5 then return "Thursday"
if num = 6 then return "Friday"
if num = 7 then return "Saturday"
end def
'=================================
def today$
'just a nice full display of todays date:
'Wednesday, October 5th, 2016
cd=current_day()
if cd = 0 then cd$="Sunday "
if cd = 1 then cd$="Monday "
if cd = 2 then cd$="Tuesday "
if cd = 3 then cd$="Wednesday "
if cd = 4 then cd$="Thursday "
if cd = 5 then cd$="Friday "
if cd = 6 then cd$="Saturday "
cm=current_month()
if cm=1 then cm$="January "
if cm=2 then cm$="February "
if cm=3 then cm$="March "
if cm=4 then cm$="April "
if cm=5 then cm$="May "
if cm=6 then cm$="June "
if cm=7 then cm$="July "
if cm=8 then cm$="August "
if cm=9 then cm$="September "
if cm=10 then cm$="October "
if cm=11 then cm$="November "
if cm=12 then cm$="December "
c=current_date()!cdd$=str$(c)
if c=1 or c=21 or c=31 then cdd$=cdd$&"st, "
if c=2 or c=22 then cdd$=cdd$&"nd, "
if c=3 or c=23 then cdd$=cdd$&"rd, "
if c>3 and c<21 then cdd$=cdd$&"th, "
if c>23 and c <31 then cdd$=cdd$&"th, "
return cd$&cm$&cdd$&str$(.SelYear)
end def
'=================================
def centertext(a$,y)
x=((.sw/2)-text_width(a$)/2)
draw text a$ at x,y*.rh
end def
'=================================
def EditText(title$, f$)
'title$ is page title.
'f$ is text filename to use/edit.
'gosub EraseButtons
graphics clear .9,.9,.9
'draw paper
shadow on
draw color 0,0,1
draw line 45*.rw,120*.rh to 45*.rw,.sh
draw line 49*.rw,120*.rh to 49*.rw,.sh
for s= 1 to 21
draw line 0,(130*.rh)+(41.3*s*.rh) to .sw,(130*.rh)+(41.3*s*.rh)
next s
'draw title bar
fill color 0,.5,1
fill rect 0,0 to .sw,110*.rh
draw color 1,1,1
centertext(title$,10)
shadow off
fill color .7,.7,.7
draw color 1,1,1
button "done" text "done" at .sw-(130*.rw),50*.rh size 125*.rw,56*.rh
draw color 1,1,1
fill color 1,.5,.5
button "clear" text "clear" at 500*.rw,50*.rh size 125*.rw,56*.rh
draw font size 26*.rw
draw text f$ at 25*.rw,65*.rh
draw font size 37*.rw
ReEdit:
'make an editor field
field "1" text "" at 60*.rw,122*.rh size .sw-(86*.rw),.sh-(381*.rh) ml
field "1" font size 36*.rw
field "1" back alpha 0
'load entry if filename exists
if file_exists(f$) then
file f$ setpos 0 'top of file
e$=""
do
file f$ readline lin$
e$=e$&lin$&chr$(10)
until file_end(f$)=1
field "1" text e$
end if
do
if button_pressed("clear") then
field "1" delete
file f$ delete
goto ReEdit
end if
until button_pressed("done")
'grab text, if any, to txt$
txt$= field_text$("1")
file f$ delete
field "1" delete
button "done" delete
button "clear" delete
'only save data to file if txt$ not empty
if txt$<>"" then
file f$ write 32 'make a file to use
file f$ setpos 0 'go to beginning
for u=1 to len(txt$)
file f$ write asc(mid$(txt$,u,1))
next u
end if
end def