Microsoft Calendar Control

When using this in VB5 is there anyway to code the individual buttons of the Calendar. (ex. if I want it to highlight the button 15 days later.) If the user can choose the month on the first calendar and there is another calendar on the page how do you code it so it is the following month?
MrBumpAsked:
Who is Participating?
 
rantanenConnect With a Mentor Commented:
Your first problem can't be solved (except by subclassing Calendar control and adding required properties/metheods).

One way to synchronize two calendar controls is shown in following sample:

Private Sub Form_Load()
    ...
    ' Start synchronization
    Calendar1_NewMonth
    ...
End Sub

Private Sub Calendar1_NewMonth()
    Calendar1.Value = 1
    If Calendar1.Month = 12 Then
        Calendar2.Year = Calendar1.Year + 1
        Calendar2.Month = 1
    Else
        Calendar2.Year = Calendar1.Year
        Calendar2.Month = Calendar1.Month + 1
    End If
End Sub

Private Sub Calendar1_NewYear()
    Call Calendar1_NewMonth
End Sub


0
 
MrBumpAuthor Commented:
Adjusted points to 100
0
 
sachinkasCommented:
Hi Mr. Bump,
Please unlock the question. I have a perfect answer to the question..

Happy VBing
From Sachinkas



0
 
rantanenCommented:
It seems that I misunderstood the question. I thought you want to highlight _two_ buttons - the present day and a day eg. 15 days later. If you only want to highlight a day a certain offset from the date selected (and use two calendars side by side), you can call following sub

Public Sub HighLightDayOffset(nDays As Integer)
    Dim NewDay As Integer
    Dim LastDay As Integer
    Const DAY_OFFSET_MAX = 30
   
    If nDays > DAY_OFFSET_MAX Then Exit Sub
   
    ' Calculate number of days in current month
    If IsDate(Calendar1.Month & "-31-" & Calendar1.Year) Then
        LastDay = 31
    ElseIf IsDate(Calendar1.Month & "-30-" & Calendar1.Year) Then
        LastDay = 30
    ElseIf IsDate(Calendar1.Month & "-29-" & Calendar1.Year) Then
        LastDay = 29
    Else
        LastDay = 28
    End If
   
    If Calendar1.Day <= 0 Or Calendar1.Day > LastDay Then Exit Sub
   
    NewDay = Calendar1.Day + nDays
   
    If NewDay <= LastDay Then
        Calendar1.Day = NewDay
        Calendar2.Day = 0
    Else
        Calendar2.Value = 1
        Calendar2.Day = NewDay - LastDay
        Calendar1.Day = 0
    End If
End Sub

This sub lets you add a certain offset to the selected date in the calendar1 and highlights the new date either in calendar1 or in calendar2.


0
 
sachinkasCommented:

Hi MrBump

      Here is the solution for your bumpy question.
Create a form and draw the controls calendar1, calendar2 and a timer timer1 and a command button command1 for the next 15 days. And paste this code. Make the timer as 1 msec.




Private Function FindDays(mon As Integer, yea As Integer) As Integer
'Function to return the number of days of a month
    Select Case mon
        Case 1, 3, 5, 7, 8, 10, 12
            FindDays = 31
        Case 2
            'Check for leap year
            'Take the century
            If yea Mod 100 = 0 Then
                If yea Mod 400 = 0 Then
                    FindDays = 29
                Else
                    FindDays = 28
                End If
            Else
                If yea Mod 4 = 0 Then
                    FindDays = 29
                Else
                    FindDays = 28
                End If
            End If
        Case 4, 6, 9, 11
            FindDays = 30
       
    End Select
   
End Function



Private Sub Command1_Click()
Dim same As Integer


same = Calendar1.Day
Calendar1.Day = Calendar1.Day + 15
If Calendar1.Day = same Then  'See if it has gone to the next month
    'if it has increase the
    'Calendar1.FirstDay
    totdays = FindDays(Calendar1.Month, Calendar1.Year) 'Function to find number of days in current month.
    'Now check if the year is changed.
    If Calendar1.Month = 12 Then
        Calendar1.Month = 1
        Calendar1.Year = Calendar1.Year + 1
    Else
        Calendar1.Month = Calendar1.Month + 1
    End If
    Calendar1.Day = 15 - (totdays - same)
End If
Calendar1.Refresh
End Sub





Private Sub Timer1_Timer()
    Calendar2.Value = Calendar1.Value
   
End Sub

Happy VBing

From Sachin


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.