Solved

Microsoft Calendar Control

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 72
VB error "Type mismatch" 2 54
Add and format columns in vb6 7 57
Visual Studio 2005 text editor 10 38
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

777 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