CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Bogotá, Colombia
    Posts
    37

    Remainder operator

    In a series of "if - then - else" statements I have the following block of code to advance the value of a Date variable by 1 or more months depending on user input.



    If Month(DateValue) = 1 then
    DateValue = DateValue + 31
    ElseIf Month(DateValue) = 2 then
    If Year(DateValue) \ 4 = 0 then
    MsgBox Year(DateValue)
    FechaValue = DateValue + 29
    else
    FechaValue = DateValue + 28
    End If

    et cetera




    Everything works fine except for the month of February during a leap year. The program never enters the first portion of the If - Then - Else statement


    If Year(DateValue) \ 4 = 0 then




    This is supposed to return the remainder of the year value divided by 4 and add 29 days rather than 28 if the remainder is 0. I thought that I might have the syntaxt for the remainder function wrong, but I never receive a compile or run-time errror of any type, it just never enters the statement.

    Anyone have an idea? thanks

    Andrew



  2. #2

    Re: Remainder operator

    You need to use the MOD operator. See http://www.freevbcode.com/ShowCode.Asp?ID=391. This will show you a foolproof whay to determine if a given year is a leap year.


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

Featured