Solved

Microsoft Calendar Control

Posted on 1998-01-09
5
206 Views
Last Modified: 2008-03-17
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?
0
Comment
Question by:MrBump
  • 2
  • 2
5 Comments
 

Author Comment

by:MrBump
ID: 1450117
Adjusted points to 100
0
 
LVL 4

Accepted Solution

by:
rantanen earned 100 total points
ID: 1450118
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
 
LVL 1

Expert Comment

by:sachinkas
ID: 1450119
Hi Mr. Bump,
Please unlock the question. I have a perfect answer to the question..

Happy VBing
From Sachinkas



0
 
LVL 4

Expert Comment

by:rantanen
ID: 1450120
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
 
LVL 1

Expert Comment

by:sachinkas
ID: 1450121

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now