Solved

Microsoft Calendar Control

Posted on 1998-01-09
5
191 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

17 Experts available now in Live!

Get 1:1 Help Now