Hallo,
Ik heb ooit eens code gevonden op een of andere website om een eigen, geprogrameerde maandkalender te maken.
Ik heb dit toen bewaard voor het geval het eens van pas zou komen en nu is de tijd gekomen dat ik het inderdaad kan gebruiken.
Deze code werkt voor 90% correct, maar bij het invullen van de dagen voor de maand februari van een schrikkeljaar, werkt het niet.
Mijn vraag bij deze is dus, kan iemand mij helpen deze code aan te passen want zelf heb ik te weinig kennis om de code volledig te
begrijpen en aan te passen. Alvast bedankt voor de interesse.
Het resultaat van deze code is volgende afbeelding:

Ik heb ooit eens code gevonden op een of andere website om een eigen, geprogrameerde maandkalender te maken.
Ik heb dit toen bewaard voor het geval het eens van pas zou komen en nu is de tijd gekomen dat ik het inderdaad kan gebruiken.
Deze code werkt voor 90% correct, maar bij het invullen van de dagen voor de maand februari van een schrikkeljaar, werkt het niet.
Mijn vraag bij deze is dus, kan iemand mij helpen deze code aan te passen want zelf heb ik te weinig kennis om de code volledig te
begrijpen en aan te passen. Alvast bedankt voor de interesse.
Het resultaat van deze code is volgende afbeelding:

Code:
Public Class UserMainForm
Dim iMonth As Integer = -1
Dim i As Integer = Now.Month
Dim yearNr As Integer = 2012
Dim ArrowRight As Boolean = False
Dim ArrowLeft As Boolean = False
Dim x1 As Date
Public Function increment()
If i = 0 Then
i = i + 1
ElseIf i = 13 Then
i = 2
Else
i = i + 1
End If
Return i
End Function
Public Function decrement()
If i = 0 Then
i = i - 1
ElseIf i = 1 Then
i = 12
Else
i = i - 1
End If
Return i
End Function
Function HideEmptyButtons()
If su1.Text = "" Then
su1.Visible = False
ElseIf su1.Text <> "" Then
su1.Visible = True
End If
If su2.Text = "" Then
su2.Visible = False
ElseIf su2.Text <> "" Then
su2.Visible = True
End If
If su3.Text = "" Then
su3.Visible = False
ElseIf su3.Text <> "" Then
su3.Visible = True
End If
If su4.Text = "" Then
su4.Visible = False
ElseIf su4.Text <> "" Then
su4.Visible = True
End If
If su5.Text = "" Then
su5.Visible = False
ElseIf su5.Text <> "" Then
su5.Visible = True
End If
If su6.Text = "" Then
su6.Visible = False
ElseIf su6.Text <> "" Then
su6.Visible = True
End If
If m1.Text = "" Then
m1.Visible = False
ElseIf m1.Text <> "" Then
m1.Visible = True
End If
If m2.Text = "" Then
m2.Visible = False
ElseIf m2.Text <> "" Then
m2.Visible = True
End If
If m3.Text = "" Then
m3.Visible = False
ElseIf m3.Text <> "" Then
m3.Visible = True
End If
If m4.Text = "" Then
m4.Visible = False
ElseIf m4.Text <> "" Then
m4.Visible = True
End If
If m5.Text = "" Then
m5.Visible = False
ElseIf m5.Text <> "" Then
m5.Visible = True
End If
If m6.Text = "" Then
m6.Visible = False
ElseIf m6.Text <> "" Then
m6.Visible = True
End If
If tu1.Text = "" Then
tu1.Visible = False
ElseIf tu1.Text <> "" Then
tu1.Visible = True
End If
If tu2.Text = "" Then
tu2.Visible = False
ElseIf tu2.Text <> "" Then
tu2.Visible = True
End If
If tu3.Text = "" Then
tu3.Visible = False
ElseIf tu3.Text <> "" Then
tu3.Visible = True
End If
If tu4.Text = "" Then
tu4.Visible = False
ElseIf tu4.Text <> "" Then
tu4.Visible = True
End If
If tu5.Text = "" Then
tu5.Visible = False
ElseIf tu5.Text <> "" Then
tu5.Visible = True
End If
If tu6.Text = "" Then
tu6.Visible = False
ElseIf tu6.Text <> "" Then
tu6.Visible = True
End If
If w1.Text = "" Then
w1.Visible = False
ElseIf w1.Text <> "" Then
w1.Visible = True
End If
If w2.Text = "" Then
w2.Visible = False
ElseIf w2.Text <> "" Then
w2.Visible = True
End If
If w3.Text = "" Then
w3.Visible = False
ElseIf w3.Text <> "" Then
w3.Visible = True
End If
If w4.Text = "" Then
w4.Visible = False
ElseIf w4.Text <> "" Then
w4.Visible = True
End If
If w5.Text = "" Then
w5.Visible = False
ElseIf w5.Text <> "" Then
w5.Visible = True
End If
If w6.Text = "" Then
w6.Visible = False
ElseIf w6.Text <> "" Then
w6.Visible = True
End If
If th1.Text = "" Then
th1.Visible = False
ElseIf th1.Text <> "" Then
th1.Visible = True
End If
If th2.Text = "" Then
th2.Visible = False
ElseIf th2.Text <> "" Then
th2.Visible = True
End If
If th3.Text = "" Then
th3.Visible = False
ElseIf th3.Text <> "" Then
th3.Visible = True
End If
If th4.Text = "" Then
th4.Visible = False
ElseIf th4.Text <> "" Then
th4.Visible = True
End If
If th5.Text = "" Then
th5.Visible = False
ElseIf th5.Text <> "" Then
th5.Visible = True
End If
If th6.Text = "" Then
th6.Visible = False
ElseIf th6.Text <> "" Then
th6.Visible = True
End If
If f1.Text = "" Then
f1.Visible = False
ElseIf f1.Text <> "" Then
f1.Visible = True
End If
If f2.Text = "" Then
f2.Visible = False
ElseIf f2.Text <> "" Then
f2.Visible = True
End If
If f3.Text = "" Then
f3.Visible = False
ElseIf f3.Text <> "" Then
f3.Visible = True
End If
If f4.Text = "" Then
f4.Visible = False
ElseIf f4.Text <> "" Then
f4.Visible = True
End If
If f5.Text = "" Then
f5.Visible = False
ElseIf f5.Text <> "" Then
f5.Visible = True
End If
If f6.Text = "" Then
f6.Visible = False
ElseIf f6.Text <> "" Then
f6.Visible = True
End If
If sa1.Text = "" Then
sa1.Visible = False
ElseIf sa1.Text <> "" Then
sa1.Visible = True
End If
If sa2.Text = "" Then
sa2.Visible = False
ElseIf sa2.Text <> "" Then
sa2.Visible = True
End If
If sa3.Text = "" Then
sa3.Visible = False
ElseIf sa3.Text <> "" Then
sa3.Visible = True
End If
If sa4.Text = "" Then
sa4.Visible = False
ElseIf sa4.Text <> "" Then
sa4.Visible = True
End If
If sa5.Text = "" Then
sa5.Visible = False
ElseIf sa5.Text <> "" Then
sa5.Visible = True
End If
If sa6.Text = "" Then
sa6.Visible = False
ElseIf sa6.Text <> "" Then
sa6.Visible = True
End If
End Function
Private Sub MonthForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthForward.Click
Dim DisplayedMonth = Now.Month
DisplayedMonth = increment()
ArrowRight = True
Dim X = Now.AddDays((Now.Day - 1) * -1).AddMonths(i - Now.Month)
Dim ldate As Date
Dim Selected As Integer
Dim bLeapYear As Boolean = Date.IsLeapYear(yearNr)
On Error Resume Next
Me.clearall()
MonthName.Text = monthstr(ldate.Month)
Dim fdate As DayOfWeek = GetFirstOfMonthDay(X)
Dim idate As Integer = 1
Dim row As Integer = 1
Do
getlabel(fdate, row).Text = idate
If idate = Selected Then
getlabel(fdate, row).Color = LCARS.LCARScolorStyles.PrimaryFunction 'sets de background color of the current day cell
End If
If fdate = DayOfWeek.Saturday Then
row += 1
End If
fdate = tdate(fdate)
idate += 1
If idate = Date.DaysInMonth((X).Year, (X).Month) + 1 Then
Exit Do
End If
Loop
If (DisplayedMonth = 13) Then
DisplayedMonth = 1
End If
If (DisplayedMonth = 1) And (ArrowRight = True) Then
yearNr = yearNr + 1
End If
If DisplayedMonth = 1 Then
MonthName.Text = "JANUARY"
End If
If DisplayedMonth = 2 Then
MonthName.Text = "FEBRUARY"
End If
If DisplayedMonth = 3 Then
MonthName.Text = "MARCH"
End If
If DisplayedMonth = 4 Then
MonthName.Text = "APRIL"
End If
If DisplayedMonth = 5 Then
MonthName.Text = "MAY"
End If
If DisplayedMonth = 6 Then
MonthName.Text = "JUNE"
End If
If DisplayedMonth = 7 Then
MonthName.Text = "JULY"
End If
If DisplayedMonth = 8 Then
MonthName.Text = "AUGUST"
End If
If DisplayedMonth = 9 Then
MonthName.Text = "SEPTEMBER"
End If
If DisplayedMonth = 10 Then
MonthName.Text = "OCTOBER"
End If
If DisplayedMonth = 11 Then
MonthName.Text = "NOVEMBER"
End If
If DisplayedMonth = 12 Then
MonthName.Text = "DECEMBER"
End If
HideEmptyButtons()
YearNumber.Text = yearNr
End Sub
Private Sub MonthBackward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthBackward.Click
Dim DisplayedMonth = Now.Month
DisplayedMonth = decrement()
ArrowLeft = True
Dim X = Now.AddDays((Now.Day - 1) * -1).AddMonths(i - Now.Month)
Dim ldate As Date
Dim Selected As Integer
On Error Resume Next
Me.clearall()
MonthName.Text = monthstr(ldate.Month)
Dim fdate As DayOfWeek = GetFirstOfMonthDay(X)
Dim idate As Integer = 1
Dim row As Integer = 1
Do
getlabel(fdate, row).Text = idate
If idate = Selected Then
getlabel(fdate, row).Color = LCARS.LCARScolorStyles.PrimaryFunction 'sets de background color of the current day cell
End If
If fdate = DayOfWeek.Saturday Then
row += 1
End If
fdate = tdate(fdate)
idate += 1
If idate = Date.DaysInMonth((X).Year, (X).Month) + 1 Then
Exit Do
End If
Loop
If (DisplayedMonth = 13) Then
DisplayedMonth = 1
End If
If (DisplayedMonth = 12) And (ArrowLeft = True) Then
yearNr = yearNr - 1
End If
If DisplayedMonth = 1 Then
MonthName.Text = "JANUARY"
End If
If DisplayedMonth = 2 Then
MonthName.Text = "FEBRUARY"
End If
If DisplayedMonth = 3 Then
MonthName.Text = "MARCH"
End If
If DisplayedMonth = 4 Then
MonthName.Text = "APRIL"
End If
If DisplayedMonth = 5 Then
MonthName.Text = "MAY"
End If
If DisplayedMonth = 6 Then
MonthName.Text = "JUNE"
End If
If DisplayedMonth = 7 Then
MonthName.Text = "JULY"
End If
If DisplayedMonth = 8 Then
MonthName.Text = "AUGUST"
End If
If DisplayedMonth = 9 Then
MonthName.Text = "SEPTEMBER"
End If
If DisplayedMonth = 10 Then
MonthName.Text = "OCTOBER"
End If
If DisplayedMonth = 11 Then
MonthName.Text = "NOVEMBER"
End If
If DisplayedMonth = 12 Then
MonthName.Text = "DECEMBER"
End If
HideEmptyButtons()
YearNumber.Text = yearNr
End Sub
Function dYear()
Dim a = Now.AddYears(-1)
x1 = a - 1
Return x1
End Function
Private Sub YearBackward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YearBackward.Click
yearNr = yearNr - 1
YearNumber.Text = yearNr
Dim DisplayedMonth = Now.Month
Dim ldate As Date
Dim Selected As Integer
On Error Resume Next
Me.clearall()
MonthName.Text = monthstr(ldate.Month)
Dim fdate As DayOfWeek = GetFirstOfMonthDay(x1)
Dim idate As Integer = 1
Dim row As Integer = 1
Do
getlabel(fdate, row).Text = idate
If idate = Selected Then
getlabel(fdate, row).Color = LCARS.LCARScolorStyles.PrimaryFunction
End If
If fdate = DayOfWeek.Saturday Then
row += 1
End If
fdate = tdate(fdate)
idate += 1
If idate = Date.DaysInMonth((x1).Year, (x1).Month) + 1 Then
Exit Do
End If
Loop
If (DisplayedMonth = 13) Then
DisplayedMonth = 1
End If
If (DisplayedMonth = 1) And (ArrowRight = True) Then
yearNr = yearNr + 1
End If
If DisplayedMonth = 1 Then
MonthName.Text = "JANUARY"
End If
If DisplayedMonth = 2 Then
MonthName.Text = "FEBRUARY"
End If
If DisplayedMonth = 3 Then
MonthName.Text = "MARCH"
End If
If DisplayedMonth = 4 Then
MonthName.Text = "APRIL"
End If
If DisplayedMonth = 5 Then
MonthName.Text = "MAY"
End If
If DisplayedMonth = 6 Then
MonthName.Text = "JUNE"
End If
If DisplayedMonth = 7 Then
MonthName.Text = "JULY"
End If
If DisplayedMonth = 8 Then
MonthName.Text = "AUGUST"
End If
If DisplayedMonth = 9 Then
MonthName.Text = "SEPTEMBER"
End If
If DisplayedMonth = 10 Then
MonthName.Text = "OCTOBER"
End If
If DisplayedMonth = 11 Then
MonthName.Text = "NOVEMBER"
End If
If DisplayedMonth = 12 Then
MonthName.Text = "DECEMBER"
End If
HideEmptyButtons()
End Sub
Private Sub YearForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YearForward.Click
yearNr = yearNr + 1
YearNumber.Text = yearNr
End Sub
Public Sub ReloadCal(ByVal ldate As Date, ByVal Selected As Integer)
On Error Resume Next
Me.clearall()
MonthName.Text = monthstr(ldate.Month)
Dim fdate As DayOfWeek = GetFirstOfMonthDay(ldate)
Dim idate As Integer = 1
Dim row As Integer = 1
Do
getlabel(fdate, row).Text = idate
If idate = Selected Then
getlabel(fdate, row).Color = LCARS.LCARScolorStyles.PrimaryFunction
End If
If fdate = DayOfWeek.Saturday Then
row += 1
End If
fdate = tdate(fdate)
idate += 1
If idate = Date.DaysInMonth((ldate).Year, (ldate).Month) + 1 Then
Exit Do
End If
Loop
End Sub
Sub clearall()
su1.Text = ""
su2.Text = ""
su3.Text = ""
su4.Text = ""
su5.Text = ""
su6.Text = ""
m1.Text = ""
m2.Text = ""
m3.Text = ""
m4.Text = ""
m5.Text = ""
m6.Text = ""
tu1.Text = ""
tu2.Text = ""
tu3.Text = ""
tu4.Text = ""
tu5.Text = ""
tu6.Text = ""
w1.Text = ""
w2.Text = ""
w3.Text = ""
w4.Text = ""
w5.Text = ""
w6.Text = ""
th1.Text = ""
th2.Text = ""
th3.Text = ""
th4.Text = ""
th5.Text = ""
th6.Text = ""
f1.Text = ""
f2.Text = ""
f3.Text = ""
f4.Text = ""
f5.Text = ""
f6.Text = ""
sa1.Text = ""
sa2.Text = ""
sa3.Text = ""
sa4.Text = ""
sa5.Text = ""
sa6.Text = ""
End Sub
Function getlabel(ByVal day As DayOfWeek, ByVal row As Integer) As LCARS.Controls.FlatButton
Select Case day
Case DayOfWeek.Sunday
Select Case row
Case 1
Return su1
Case 2
Return su2
Case 3
Return su3
Case 4
Return su4
Case 5
Return su5
Case 6
Return su6
End Select
Case DayOfWeek.Monday
Select Case row
Case 1
Return m1
Case 2
Return m2
Case 3
Return m3
Case 4
Return m4
Case 5
Return m5
Case 6
Return m6
End Select
Case DayOfWeek.Tuesday
Select Case row
Case 1
Return tu1
Case 2
Return tu2
Case 3
Return tu3
Case 4
Return tu4
Case 5
Return tu5
Case 6
Return tu6
End Select
Case DayOfWeek.Wednesday
Select Case row
Case 1
Return w1
Case 2
Return w2
Case 3
Return w3
Case 4
Return w4
Case 5
Return w5
Case 6
Return w6
End Select
Case DayOfWeek.Thursday
Select Case row
Case 1
Return th1
Case 2
Return th2
Case 3
Return th3
Case 4
Return th4
Case 5
Return th5
Case 6
Return th6
End Select
Case DayOfWeek.Friday
Select Case row
Case 1
Return f1
Case 2
Return f2
Case 3
Return f3
Case 4
Return f4
Case 5
Return f5
Case 6
Return f6
End Select
Case DayOfWeek.Saturday
Select Case row
Case 1
Return sa1
Case 2
Return sa2
Case 3
Return sa3
Case 4
Return sa4
Case 5
Return sa5
Case 6
Return sa6
End Select
End Select
End Function
Private Function GetFirstOfMonthDay(ByVal ThisDay As Date) As DayOfWeek
Dim tday As DayOfWeek = ThisDay.DayOfWeek
Dim tint As Integer = ThisDay.Day
If tint = 1 Then
Return tday
Exit Function
End If
Do
tint -= 1
tday = ydate(tday)
If tint = 1 Then Exit Do
Loop
Return tday
End Function
Private Function ydate(ByVal tday As DayOfWeek) As DayOfWeek
Dim rday As DayOfWeek
Select Case tday
Case DayOfWeek.Sunday
rday = DayOfWeek.Saturday
Case DayOfWeek.Monday
rday = DayOfWeek.Sunday
Case DayOfWeek.Tuesday
rday = DayOfWeek.Monday
Case DayOfWeek.Wednesday
rday = DayOfWeek.Tuesday
Case DayOfWeek.Thursday
rday = DayOfWeek.Wednesday
Case DayOfWeek.Friday
rday = DayOfWeek.Thursday
Case DayOfWeek.Saturday
rday = DayOfWeek.Friday
End Select
Return rday
End Function
Private Function tdate(ByVal tday As DayOfWeek) As DayOfWeek
Dim rday As DayOfWeek
Select Case tday
Case DayOfWeek.Sunday
rday = DayOfWeek.Monday
Case DayOfWeek.Monday
rday = DayOfWeek.Tuesday
Case DayOfWeek.Tuesday
rday = DayOfWeek.Wednesday
Case DayOfWeek.Wednesday
rday = DayOfWeek.Thursday
Case DayOfWeek.Thursday
rday = DayOfWeek.Friday
Case DayOfWeek.Friday
rday = DayOfWeek.Saturday
Case DayOfWeek.Saturday
rday = DayOfWeek.Sunday
End Select
Return rday
End Function
Public Function monthstr(ByVal month As Integer) As String
Select Case month
Case 1
Return "January"
Case 2
Return "Febuary"
Case 3
Return "March"
Case 4
Return "April"
Case 5
Return "May"
Case 6
Return "June"
Case 7
Return "July"
Case 8
Return "August"
Case 9
Return "September"
Case 10
Return "October"
Case 11
Return "November"
Case 12
Return "December"
End Select
End Function
Private Sub UserMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReloadCal(Date.Today, Date.Today.Day)
YearNumber.Text = Now.Year
HideEmptyButtons()
End Sub
End Class