Results 1 to 3 of 3

Thread: Calculating Staff Holiday Days

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    4

    Calculating Staff Holiday Days

    Hello

    Currently I was making a program that will store staff holidays, with a form they can fill out when they take some.

    The form has Holiday Start and Holiday Finish as 2 Date Fields.

    Also 7 Check boxes(Monday to Sunday) so they can tick which days they would normally work.

    The problem i have is then we need to know how many days are being taken, for example.

    If they choose
    From 14/12/2010 To 16/12/2010
    This is
    14th.Tuesday 15th.Wednesday 16.Thursday

    But they have ticked they only work Tuesdays and Thursdays this means they would have only took 2 days holiday.

    How could i calculate this say if an employee took 1 month?
    Would i have to check everyday/date? or is there a more efficient way?
    Any help Appreciated

    Thanks,
    -Dual

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculating Staff Holiday Days

    Why not have a single checkbox which equals one month?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    4

    Re: Calculating Staff Holiday Days

    I managed to do it by making a function looping through each day in-between the selected dates they want holiday.

    Then if they had checked a day count it as a day holiday.

    Seems long winded, but works. The screen shot may give you a better idea of what i was trying to achieve.



    Code:
    Function FindDays(ByVal fromdate As Date, ByVal todate As Date)
            Dim AmountofDaysTaken As Integer = 0
            If todate.Date < fromdate.Date Then Exit Function
            While fromdate.Date <= todate.Date
                Select Case fromdate.DayOfWeek.ToString()
                    Case "Monday"
                        If mondaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Tuesday"
                        If tuesdaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Wednesday"
                        If wednesdaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Thursday"
                        If thursdaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Friday"
                        If fridaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Saturday"
                        If saturdaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                    Case "Sunday"
                        If sundaychk.Checked Then AmountofDaysTaken = AmountofDaysTaken + 1
                End Select
                Debug.Print(fromdate.Date & " " & todate.Date & " " & fromdate.DayOfWeek.ToString())
                My.Application.DoEvents()
                fromdate = fromdate.AddDays(1)
            End While
            Return AmountofDaysTaken
        End Function
    -Dual

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