A Function to detect Holidays in your VBS Script

This is basically a function that checks if the current date is listed in a text file and then returns a true or False. The txt file should have a list of holiday dates.

' FileOpen iomode Values 
Const fsoForReading = 1 
  
' holiday Filename 
Const sHolidays = "c:\scripts\holiday.txt" 
  
Function IsHoliday(ByVal vDate) 
  
    Dim fso, file, sLine, bReturn
  
    bReturn = False 

    ' Create FileSystemObejct 
    fso = CreateObject("Scripting.FileSystemObject") 
  
    ' Open text file 
    Set file = fso.OpenTextFile(sHoliday, fsoForReading) 
  
    Do While (Not (file.AtEndOfStream)) And (Not bReturn) 
        sLine = file.ReadLine 
        If IsDate(sLine) Then 
            If DateDiff("d", vDate, CDate(sLine)) = 0 Then 
                bReturn = True 
            End If 
        End If 
    Loop 
    file.Close() 
  
    file = Nothing 
    fso = Nothing 
  
    IsHoliday = bReturn 
  
End Function

Here is how the holiday file should be formatted

25.12.2002
26.12.2002
01.01.2003
18.04.2003
21.04.2003
01.05.2003
11.05.2003
29.05.2003
09.06.2003
03.10.2003
25.12.2003
Advertisements

About Paul Cardelli, CISSP
Cyber Security Analyst, and computer guru

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: