Solved

VB .Net networkdays function Analysis toolpak support help requested.

Posted on 2004-10-13
3
910 Views
Last Modified: 2009-04-30
I am new to VB .NET and am wishing to create an application that uses the networkdays function of the analysis toolpak addin available in excel to generate number of working days between start and end dates within a table, taking into account the holidays held within a separate table.
Can you tell me if this is possible and how best to proceed?

thanks
Jase105
0
Comment
Question by:CorpSystems
  • 2
3 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12298340
Busines days between 2 dates

Function BusinessDateDiff(ByVal startDate As Date, ByVal endDate As Date,
 Optional ByVal saturdayIsHoliday As Boolean = True) As Integer
    Dim incr As Integer

    ' incr can be +1 or -1
    If startDate < endDate Then incr = 1 Else incr = -1

    Do Until startDate = endDate
        ' skip to previous or next day
        startDate = startDate.AddDays(incr)
        If startDate.DayOfWeek <> DayOfWeek.Sunday AndAlso _
            (startDate.DayOfWeek <> DayOfWeek.Saturday Or Not
saturdayIsHoliday) Then
            ' if it's a weekday add/subtract one to the result
            BusinessDateDiff += incr
        End If
    Loop
    ' when the loop is exited the function name contains the correct
result
End Function


There are different holidays for every company. I guess that you have to calculate holidays from your table and subtract it from the total. Don't forget to check if the holiday is on the week end.
0
 

Author Comment

by:CorpSystems
ID: 12299489
thanks for your idea.
Does this mean the excel networkdays function is not available as an addin to VB .Net? ie that I cannot do the equivalent
networkdays(start_date, end_Date, holidays) type call within a .NET program?
I'd rather not reinvent the wheel if there is a COM class I can reference in .NET  which contains this functionality.

Jase105
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
ID: 12300214
I don't think so.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question