Cursussen/Courses Codesnippets     Top 
B4A-calendar - Calendar notes


Assignment
A calendar with notes for 1 year.
If you add the following lines of code to the calendar_library you can create an app to add, change or delete notes for any given date.
Changes to the calendar_library (before the lbl.tag statement from the inner loop in the subroutine set_month_panel):
If File.Exists(File.DirInternal,DateUtils.SetDate(yr,mnth,daynumber) & "_notes.txt") Then
	If daynumber = currentday And mnth = currentmonth And yr = currentyear Then
		Private lbl As Label = set_label(daynumber,Colors.ARGB(100,255,165,0),"lblday")
	Else
		Private lbl As Label = set_label(daynumber,Colors.ARGB(100,255,255,0),"lblday")	
	End If
End If
lbl.Tag = DateUtils.SetDate(yr,mnth,daynumber)
In the newly created app you can do something like this:
In the subroutine B4Xpage_Appear:

•	Initialize a calendar object
• Initialize a panel object
• Loop from 1 to 12
o Set the panel object to the cal.set_mont_panel (i,2022,””)
o Add the panel to a scrollview object (from designer / full screen)
• Set the scrollview width and height
• Scroll in the scrollview to the current month
o pos = 1dip + (pnl.Height * (currentmonth-1))
o sv1.ScrollToNow(pos) ' set inner panel in designer to 15000 for the scrolling to work!
In the subroutine cal_dayclick:

•	get the year, month and day from the dayticks to produce a date string
• set a note variable to the result of a load_note(dayticks) subroutine (like in the B4A-lists tutorial)
• if the note is empty show an add_dialog (see the B4A-lists tutorial)
• if the note is not empty show a change_dialog (see the B4A-lists tutorial)
Provide the other subroutines:
• save a note: save_note(ticks, note)
• load a note: load_note(ticks)
• show_add_dialog(strdate)
• show_change_dialog(note, strdate)
• copy the subroutine setup_dialog from the B4A-lists project

The text filename must be: ticks & "_notes.txt" (see the calendar_library changes)
Here are some screenshots of how it should look like:


X

Paragraphs

Assignment