|
-
Jan 25th, 2000, 08:11 AM
#1
Thread Starter
New Member
HELP I am a frustrated student that seems to have only part of the picture for a calender that contains a module and 12(?) forms. I understand the "for x" and such. Do I need a select case for each of the months? What about the leap year? HELP
-
Jan 25th, 2000, 10:57 AM
#2
PowerPoster
-
Jan 26th, 2000, 01:25 AM
#3
Sure. You would need only 1 (one) form.
Add 2 comboboxes (cboMonth and cboYear) and MSFlexGrid control (grdCalendar). Copy this code to your form:
Code:
Option Explicit
Private mIsFinishedLoading As Boolean
Public Function GetLasDayOfMonth(pintMonth As Integer, pintYear As Integer)
GetLasDayOfMonth = Day(DateSerial(pintYear, pintMonth + 1, 0))
End Function
Public Sub ReloadCalendar(pGrid As MSFlexGrid, pintMonth As Integer, pintYear As Integer)
Dim intLastDay As Integer
Dim i As Integer
Dim intDay As Integer
Dim intRow As Integer
Dim intCol As Integer
Dim datDate As Date
'Get the last day of the selected month
intLastDay = GetLasDayOfMonth(cboMonth.ListIndex + 1, cboYear.List(cboYear.ListIndex))
'Fill the Grid with Calendar days
With pGrid
intRow = 1
.Rows = 1
.Rows = 2
For i = 1 To intLastDay
datDate = CDate(pintMonth & "/" & i & "/" & pintYear)
For intDay = 0 To 6
'Check to see what day it is
If .TextMatrix(0, intDay) = Format(datDate, "ddd") Then
intCol = intDay
Exit For
End If
Next
.TextMatrix(intRow, intCol) = Day(datDate)
If intCol = 6 Then
intCol = 0
.Rows = .Rows + 1
intRow = intRow + 1
End If
Next
End With
End Sub
Private Sub cboMonth_Click()
Dim intYear As Integer
intYear = Val(cboYear.List(cboYear.ListIndex))
ReloadCalendar grdCalendar, cboMonth.ListIndex + 1, intYear
End Sub
Private Sub cboYear_Click()
Dim intYear As Integer
If mIsFinishedLoading Then
intYear = Val(cboYear.List(cboYear.ListIndex))
ReloadCalendar grdCalendar, cboMonth.ListIndex + 1, intYear
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim strDay As String
With grdCalendar
.FixedCols = 0
.Cols = 7
For i = 1 To 7
strDay = Format(DateAdd("w", i, #1/1/2000#), "ddd")
.TextMatrix(0, i - 1) = strDay
.ColWidth(i - 1) = 600
Next
End With
'Load Year
For i = 2000 To 2020
cboYear.AddItem i
Next
cboYear.ListIndex = 0
'Load Month
For i = 1 To 12
cboMonth.AddItem Format(DateAdd("m", i, #12/1/2000#), "mmmm")
Next
cboMonth.ListIndex = 0
cboYear.ListIndex = 0
mIsFinishedLoading = True
End Sub
Good luck.
------------------
Serge
Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 01-26-2000).]
-
Jan 26th, 2000, 06:27 AM
#4
Addicted Member
or you could use the calendar control...
if i'm not mistaken you can find it if you click on "Add component..." on the toolbox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|