Results 1 to 4 of 4

Thread: HELP !! vb6 code for a 12 month calendar

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Everett
    Posts
    1

    Post

    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

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    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
    [email protected]
    If it ain't broke - don't fix it

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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).]

  4. #4
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232

    Post

    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
  •  



Click Here to Expand Forum to Full Width