Results 1 to 10 of 10

Thread: some kind of perpetual calender

  1. #1
    s2000
    Guest

    Angry

    /the task
    write a program which calculates the day of the week for any date past and future, falling after 12/31/1582 to make a calendar for a specified month and year.

    /the problem
    I am having trouble with the code

    does anyone know where I can find coding on the net or a similar project on the net that I can use as a guideline?

    any help would be appreciated

    thanks!
    Lexi
    [email protected]

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You can get the day of the week like so. I tried it with the date you gave and it seemed to work okay.
    Code:
    Dim strDay As String
    strDay = Format(#6/14/1890#, "dddd")

  3. #3
    Dreamlax
    Guest
    I can't belive it's that simple. I thought it had something to do with this and something to do with that and VB constants and stuff. Oh well, next time I know what to do .

  4. #4
    s2000
    Guest
    This is the whole project - very confusing - any help?


    Perpetual Calendar Project


    Introduction

    The Gregorian calendar was introduced in 1582. You are being asked to write a program which calculates the day of the week for any date past and future, falling after 12/31/1582 to make a calendar for a specified month and year.

    Overview of the Problem
    a. Request the month, day, and year as numeric inputs. Use either single or multiple textboxes to capture the user’s inputs. Single text boxes make it necessary to parse the data to separate the month day and year but simplifies the user interface with the program.

    b. After you determine the maximum number of days in the month, check the user’s inputs for validity. If you determine an error in the input, notify the user with an error message or frowning face symbol and allow him to correct the errant month, day or year.
    The maximum number of days in each month is constant for all months except February, which is usually 28 days except leap years, when February has 29 days.

    A year is said to be a leap year if all of the following conditions are met.
    Any years divisible by 4 is considered a leap year, with the exception of those years divisible by 100 and not by 400. By this rule, the years 1600 and 2000 are leap years but the years 1700, 1800, and 1900 are not. If you are clever, this leap year condition can be tested with a single “If” statement. See chapter 5 of our textbook for more details on the “If” and the “Select Case”

    Algorithm

    Use the following algorithm to determine the day of the week for a given date.

    1) Treat January and February as the 13th and 14th months of the previous year, respectively. Thus, 1-10-98 is treated as 13-10-1997. Similarly, 2-10-1998 becomes 14-10-1997.

    2) Let m, d, and y denote the month, day, and year, respectively. Similarly,
    2-10-1998 becomes 14-10-1997. Compute w, where

    w = d + 2*m + Int((3/5)*(m +1)) + y + Int(y/4) – Int(y/100) + Int(y/400) + 2

    3) The remainder of w divided by 7 denotes the day of the week, where 0 is Saturday, 1 is Sunday, 2 is Monday, and so on. Hint : See the “Mod” function described on page 126 – Comment 8 of our text.

  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Use the following algorithm to determine the day of the week for a given date
    Do you have to use the algrothim. That would take an age to code, but the alternative is only 1 line!!

  6. #6
    s2000
    Guest

    100 lines

    well the whole project is supposed to be about 100 lines.

  7. #7
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Adding validity check for valid dates:

    To a project add a text box and a command button, then add code behind form.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    If IsDateValid(Text1) Then
        MsgBox Format(Text1, "dddd")
    Else
        MsgBox "You have Not entered a valid Date :-(."
    End If
    End Sub
    
    
    Function IsDateValid(strDate As String) As Boolean
    'stop users from entering dates Not valid according To locale settings
    'e.g. If dd/mm/yy local settings Then 12/24/2000 = invalid, 24/12/2000 = valid
    Dim pos As Integer
    pos = InStr(1, strDate, "/")
    If IsDate(strDate) Then If Left(strDate, pos) = Left(CDate(strDate), pos) Then IsDateValid = True
    End Function

  8. #8
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    A shortcut to leap year calculation, why reinvent the wheel:

    Code:
    Function IsLeapYear(ByVal sYear As String) As Boolean
        If Month(DateSerial(sYear, 2, 29)) = 2 Then IsLeapYear = True
    End Function

  9. #9
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Must be bored to reinvent the wheel , here it is:

    Code:
    Function IsLeapYear(ByVal sYear As String) As Boolean
        If sYear Mod 400 = 0 Then
            IsLeapYear = True
        ElseIf sYear Mod 100 = 0 Then
            IsLeapYear = False
        ElseIf sYear Mod 4 = 0 Then
            IsLeapYear = True
        End If
    End Function

  10. #10
    anoop007
    Guest
    This is a QBasic program i did a long time ago (when i didn't have VB) to create a perpetual calender..
    displays calender of any year..

    Try to convert this somehow to VB!

    Code:
    On ERROR GoTo 999
    Dim M$(12), D(12), day$(7)
    For I = 1 To 12
    Read M$(I), D(I)
    Next I
    For I = 1 To 7
    Read day$(I)
    Next I
    CLS
    
    140 Print "Super Calender v2.0"
    Print "By Anoop Sankar, March 1999"
    Print "To display BC years, use a negative sign"
    Print
    Input "Enter year,0 to stop : ", Y
    
    If Y > 0 Then year$ = Str$(Y) + " AD" Else year$ = Str$(Abs(Y)) + " BC"
    If Y = 0 Then End
    yr = Int(Y / 100)
    y1 = yr / 4
    sy = (y1 * 6 + (yr - y1) * 5) Mod 7 + 1
    If sy = 7 Then sy = 0
    p1 = (Y / 100 - yr) * 100: P = Int(p1)
    If p1 >= (P + .5) Then P = P + 1
    nly = P / 4
    
    While nly > 7
    nly = nly - 7
    Wend
    
    sly = sy + (3 - (2 * (nly - 1)))
    
    While sly < 0
    sly = sly + 7
    Wend
    
    dfly = P Mod 4
    If dfly <> 0 Then dfly = dfly + 1
    ast = sly + dfly
    
    While ast > 6
    ast = ast - 7
    Wend
    
    If (Y / 4 = Int(Y / 4)) And (Y Mod 100 <> 0) Or (Y / 400 = Int(Y / 400)) Then D(2) = 29
    c = ast * 10
    CLS
           
            For I = 1 To 12
                    If I / 2 <> Int(I / 2) Then Print TAB(37); year$: Print
                    Print : Print
                    Print TAB(38); M$(I): Print
                    R = 0
                           
                            For J = 1 To 7
                                    Print TAB(R); day$(J);
                                    R = R + 10
                            Next J
                    Print
                            For K = 1 To D(I)
                                    Print TAB(c + 4); K;
                                    c = c + 10
                                    If c > 60 Then c = 0: Print
                            Next K
                    If I / 2 = Int(I / 2) Then Print : Print "Press any key to continue...": Do: Loop Until INKEY$ <> "": CLS
            Next I
    D(2) = 28: CLS : GoTo 140
    DATA January,31,February,28,March,31,April,30,May,31,June,30,July,31,August,31
    DATA September,30,October,31,November,30,December,31
    DATA Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
    
    999 BEEP: Print "Error    :"; ERR; "in line"; ERL
    Do: Loop Until INKEY$ <> ""
    If ERR = 6 Then Print "OVERFLOW" Else Print "UNKNOWN ERROR"
    Print "CLEAN EXIT"
    End

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