Click to See Complete Forum and Search --> : HELP !! vb6 code for a 12 month calendar
cristjs
Jan 25th, 2000, 07:11 AM
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
chrisjk
Jan 25th, 2000, 09:57 AM
Little bit of advice - don't tell anyone you are a student programmer. A while ago there was this huge discussion about how students simply use this BB to get last minute answers to problems they can't be arsed to look in help for, and usually had left their project to the last minute before deadline.
Also, I know you haven't, but make sure you don't put the subject as something like "URGENT -PLEASE HELP, DEADLINE TOMORROW" or whatever. Guaranteed not to get a response.
With regard to your question (finally :)), could you be a little more specific. What picture? A little explaination makes it all the more easier.
And your nickname thingy looks remarkably like mine!! Magic
regards,
------------------
- Chris
chris.kilhams@btinternet.com
If it ain't broke - don't fix it :)
Serge
Jan 26th, 2000, 12:25 AM
Sure. You would need only 1 (one) form.
Add 2 comboboxes (cboMonth and cboYear) and MSFlexGrid control (grdCalendar). Copy this code to your form:
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
sdymkov@microage.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
[This message has been edited by Serge (edited 01-26-2000).]
pardede
Jan 26th, 2000, 05:27 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.