Link to home
Start Free TrialLog in
Avatar of MrBump
MrBump

asked on

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?
Avatar of MrBump
MrBump

ASKER

Adjusted points to 100
ASKER CERTIFIED SOLUTION
Avatar of rantanen
rantanen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Mr. Bump,
Please unlock the question. I have a perfect answer to the question..

Happy VBing
From Sachinkas



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.



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