Results 1 to 11 of 11

Thread: filtering data with fuctions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21

    filtering data with fuctions

    I dont seem to be explaining this right but i will try again

    I have a user enter a date into an imput box
    if the date is valid i need to run it throught a function to determine if it is a leap year or not
    i have it worked out so if the valid date is divisible by four it is a leap year if it has decimals its not
    i dont know where to take it from there
    how can i choose that date is a leap year from
    my choices being with or with out decimal
    if (vbdate is ??????) then
    picbox.print vbdate & " is a leap year."
    else
    not(vbdate)

    picbox.print vbdate & " is not a leap year."
    end if

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    MSDN

    VB Code:
    1. Function LeapYear(ByVal YYYY As Long) As Boolean
    2.   LeapYear = YYYY Mod 4 = 0 And (YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0)
    3. End Function
    4.  
    5. Function LeapYear2(ByVal YYYY As Long) As Boolean
    6.    LeapYear2 = Month(DateSerial(YYYY, 2, 29)) = 2
    7. End Function
    -= a peet post =-

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21
    bump
    due to the fact that i dont understand the commands
    i need easier more basic commands
    due to my lack of understanding

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    don't think u will get it any easier or more basic than that

    what commands do u not understand ?
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    The rules for determining if a given date falls during a leap year depend on three criteria:

    Is the year evenly divisible by 4? If so, it is a leap year,

    unless...


    Is the year evenly divisible by 100? (for example, 1500?) If so, it is not a leap year,

    unless...


    Is the year evenly divisible by 400? If so, it is a leap year.

    that is what this function do :

    VB Code:
    1. Function LeapYear(ByVal YYYY As Long) As Boolean
    2.   LeapYear = YYYY Mod 4 = 0 And (YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0)
    3. End Function
    -= a peet post =-

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    and the mod operator is used to divide two numbers and return only the remainder.

    hope that explains it all
    -= a peet post =-

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21
    i dont understand the mod command
    i havent covered that in class yet
    could you give me a quick synopsis??

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by peet
    and the mod operator is used to divide two numbers and return only the remainder.

    hope that explains it all
    -= a peet post =-

  9. #9

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Yes, and here is the full story

    MSDN
    Mod Operator
    Description

    Used to divide two numbers and return only the remainder.

    Syntax

    result = number1 Mod number2

    The Mod operator syntax has these parts:

    Part
    Description



    result
    Required; any numeric variable.

    number1
    Required; any numeric expression.

    number2
    Required; any numeric expression.




    Remarks

    The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the following expression, A (result) equals 5.

    A = 19 Mod 6.7
    Usually, the data type of result is a Byte, Byte variant, Integer, Integer variant, Long, or Variant containing a Long, regardless of whether or not result is a whole number. Any fractional portion is truncated. However, if any expression is Null, result is Null. Any expression that is Empty is treated as 0.

    See Also

    Operator precedence.

    Example

    This example uses the Mod operator to divide two numbers and return only the remainder. If either number is a floating-point number, it is first rounded to an integer.

    VB Code:
    1. Dim MyResult
    2. MyResult = 10 Mod 5                        ' Returns 0.
    3. MyResult = 10 Mod 3                        ' Returns 1.
    4. MyResult = 12 Mod 4.3                        ' Returns 0.
    5. MyResult = 12.6 Mod 5                        ' Returns 3.
    Example (Microsoft Excel)

    This example sets the column width of every other column on Sheet1 to 4 points.
    VB Code:
    1. For Each col In Worksheets("Sheet1").Columns
    2.     If col.Column Mod 2 = 0 Then
    3.         col.ColumnWidth = 4
    4.     End If
    5. Next col
    This example sets the row height of every other row on Sheet1 to 4 points.
    VB Code:
    1. For Each rw In Worksheets("Sheet1").Rows
    2.     If rw.Row Mod 2 = 0 Then
    3.         rw.RowHeight = 4
    4.     End If
    5. Next rw
    This example selects every other item in list box one on Sheet1.
    VB Code:
    1. Dim items() As Boolean
    2. Set lbox = Worksheets("Sheet1").ListBoxes(1)
    3. ReDim items(1 To lbox.ListCount)
    4. For i = 1 To lbox.ListCount
    5.     If i Mod 2 = 1 Then
    6.         items(i) = True
    7.     Else
    8.         items(i) = False
    9.     End If
    10. Next
    11. lbox.MultiSelect = xlExtended
    12. lbox.Selected = items
    -= a peet post =-

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    21
    thank you very much

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