I am populating a panel as a month view calendar.
Within the panel I have panels 7 across X 6 down to form a "grid" of 42 panels.
Each panel has a Label that will represent the Date.
The labels are named, top left "lblP1" to bottom right "lblP42"
In order to start the first day of the month at the correct position, I am using the following code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private lblP1 As Label
Private lblP2 As Label
Private lblP3 As Label
' and the others too... up to lblP42
Private calLabels(42) As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
calLabels = Array As Label(lblP1,lblP2,lblP3, ...)
Sub Globals
Dim days(42) As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
DateTime.DateFormat="yyyy-MM-dd"
setup
update(4,2017) 'update to april 2017
End Sub
Sub setup
For x=0 To 41
Dim l As Label
l.Initialize("")
l.Text="x" 'just for texting the setup
l.Gravity=Gravity.CENTER
days(x)=l
Activity.AddView(l,(x Mod 7) * 14%x,Floor(x/7)*5%x,14%x,7%x)
Next
End Sub
Sub update(m As Int,y As Int)
Dim wd,md,dt As Long
For x=0 To 41
days(x).text=""
Next
dt=DateTime.DateParse(y&"-"&m&"-01")
wd=DateTime.GetDayOfWeek(dt)-1
md=DateTime.GetDayOfMonth(DateTime.Add(dt,0,1,0)-DateTime.TicksPerDay)
For x=0 To md-1
days(wd+x).Text=x+1
Next
End Sub