VB Script - Check Text file for date

Posted on 2005-04-14
Last Modified: 2010-05-02
Hi ,
I want to put a script together that checks an output from another system ( output is the date a service ran in a text file )
Need to pull the date , do a compare and send an email if theres a gap of more than 50 mins between now() and the time in the file.

Will scedule the script to run every 5 min...

Any ideas?

Question by:stephengriffin
    LVL 23

    Expert Comment

    In this text file is there only one date at any one time or are there multiple dates that have to be searched through or do you just take the last date that is in there out of all of them or what ?
    LVL 1

    Author Comment

    Hi , the text will be replaced each time within the file.. ie it will just be a date time (now function)

    LVL 10

    Accepted Solution

    Hi stephengriffin,
    This should do the trick. Please note I haven't actually tested this script, but have extracted (and modified) code from working (VB) software on our site. Don't forget to make the changes indicated in the code before running. Just copy & paste into a .vbs file (Suggest DateCheck.vbs), edit it, and run it.

    Regards .. Alan

    Private Const ForReading = 1
    Private Const MapiTo = 1
    Private Const Mapicc = 2
    Private Const MapiBcc = 3
    Private Const fPath = "C:\Time.log" ' Put path to file in here
    Dim fso, f, DateAndTime, OSession, Omessage, Recip
    Set fso = CreateObject("Scripting.filesystemobject")
    Set f = fso.OpenTextFile(FPath, ForReading)
    While Trim(f.ReadLine) = "" ' Skip empty lines
    DateAndTime = CDate(Trim(f.ReadLine))
    Set f = Nothing
    If DateDiff("m",DateAndTime, Now) > 50 Then
          Set OSession = CreateObject(MAPI.Session)
          ' Change anything in '<>' to match your environment This is the Exchange account sending the message
          OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
          'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
          Set OMessage = OSession.Outbox.Messages.Add
          ' Repeat this section for all recipients
          Set Recip = OMessage.Recipients.Add
          Recip.Name = "<Who's it going to>"
          Recip.Type = MapiTo ' Subsequent recipients should be Mapicc oe MapiBcc
          ' To here
          Set Recip = Nothing
          OMessage.Subject = "This is your message Subject"
          OMessage.Text = "This is the message Body"
          OMessage.Text = OMessage.text & CHR(10) & "Add this if more than one line"
          Set OMessage = Nothing
          Set OSession = Nothing
    End if

    LVL 10

    Expert Comment

    Sorry left some extraneous code in there:
    >    OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
    >     'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")

    Should be:
        OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
    i.e delete the line with my test names in, and uncomment the other.

    .. Alan
    LVL 10

    Expert Comment

    Sorry again, we're checking for 50 months difference here:
    If DateDiff("m",DateAndTime, Now) > 50 Then
    Should be:
    If DateDiff("n",DateAndTime, Now) > 50 Then

    .. Alan
    LVL 1

    Author Comment

    Sorry Alan ! I thought id awared points!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now