Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Business Funtions, dates specifically

Status
Not open for further replies.

VERSA

IS-IT--Management
Feb 28, 2003
22
US
Hello Everyone,

Does anyone know of a 3rd party vendor that sells a library of business functions? I am looking for functions that allow to add and substract 2 working days. It also needs to be able to take into account holidays.

Unfortunately, I am not using VB IDE, but rather an ERP system that provides me with a VB.net editor window; which I can use to write my own code.

I will need the code itself. The ERP system does not allow installation of components or such.

Any suggestions would be greatly appreciated.

Percy
 
I don't know of anyone who provides such a library, but the code isn't hard to come up with. You'll have to populate your own holidays though.

Code:
Dim OriginalDate As Date = Today
Dim DesiredDate As Date = OriginalDate
Dim DaysToRemove As Integer = 2
Dim DaysRemoved As Integer = 0

While DaysRemoved < DaysToRemove
  DesiredDate = DesiredDate.AddDays(-1)
  If Not DesiredDate.DayOfWeek = DayOfWeek.Saturday And _
     Not DesiredDate.DayOfWeek = DayOfWeek.Sunday Then
    Dim dsHolidays As New DataSet
    dsHolidays.ReadXml("C:\Holidays.xml")
    Dim drs() As DataRow = dsHolidays.Tables("Holidays").Select("Date = '" & DesiredDate.ToString & "'")
    If drs.Length = 0 Then DaysRemoved += 1
  End If
End While

MsgBox(OriginalDate.ToString & " -2 days, accounting for holidays and weekends is " & DesiredDate.ToString)

Your Holiday.xml file would look like this:
Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Holidays>
    <Date>8/15/2007 12:00:00 AM</Date>
    <Date>10/31/2007 12:00:00 AM</Date>
  </Holidays>
</NewDataSet>

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick,
I created the XML file and placed it in my C drive.

Then copy and pasted the code and associated it to a button in a form.

When I click on the button, I received.

An unhandled exception of type 'System.Data.EvaluateException' occurred in system.data.dll

Additional information: Cannot find column [Date].

Any assistance would be greatly appreciated.

Thanks,

Percy
 
Whoops, sorry about that. Poorly formed XML. Should be:

Code:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Holidays>
    <Date>8/15/2007 12:00:00 AM</Date>
  </Holidays>
  <Holidays>
    <Date>10/31/2007 12:00:00 AM</Date>
  </Holidays>
</NewDataSet>

The easiest way to generate the XML is to create a dataset, add a table named "Holidays" add a column to that table called "Date" then start adding rows. Once you have all of your dates added, you can use Dataset.WriteXML to save it to disk. Once you figure that out, it becomes really easy to set up a small user interface to allow anyone to go in and add/remove holidays.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top