Question calculate the addition of days

kermitforney

New member
Joined
Aug 5, 2008
Messages
1
Programming Experience
3-5
Not very familiar with VB and wondered if anyone could point me in the right direction. I need to have the Me.txtNextSvs.Text "Box" calculate the addition of days, but exclude weekends and holidays.

Any posts on the net or explanations are more than welcome. Thanks guys!

Here is the code currently in production.

Me.txtLastSvs.Text = Today()
Me.txtNextSvs.Text = Now.Date.AddDays(CInt(dst.Tables(0).Rows(0).Item("tntServiceFreqDays")))
 
VB.NET:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim holidays As New List(Of Date)
        holidays.Add(New Date(2008, 12, 25))
        holidays.Add(New Date(2008, 1, 1))
        holidays.Add(New Date(2008, 8, 6))
        holidays.Add(New Date(2008, 8, 11))

        TextBox1.Text = NextWorkDay(holidays)
    End Sub

VB.NET:
    Private Function NextWorkDay(ByVal Holidays As List(Of Date)) As Date
        Dim LastServiceDate As Date = Date.Today()
        Dim NextServiceDate As Date

        Dim AddedDays As Integer = 1

        While LastServiceDate.AddDays(AddedDays).DayOfWeek = DayOfWeek.Saturday _
            OrElse LastServiceDate.AddDays(AddedDays).DayOfWeek = DayOfWeek.Sunday _
            OrElse Holidays.Contains(LastServiceDate.AddDays(AddedDays))
            AddedDays += 1
        End While

        NextServiceDate = LastServiceDate.AddDays(AddedDays)

        Return NextServiceDate
    End Function

Should be able to incorporate your own holiday table set the first date to try:
VB.NET:
AddedDays = CInt(dst.Tables(0).Rows(0).Item("tntServiceFreqDays"))
 
Back
Top