Link to home
Start Free TrialLog in
Avatar of itbabe
itbabe

asked on

Script to check whether text has been added to text file

I am using the following script to check whether a string being 'hello' was added to the following textfile.

But at line 16  being If LastCount = -1 Then , i get an error, see attachment


MyString = "hello"
MyTextFile = "C:\Documents and Settings\admhomaa\Desktop\test.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set myRegExp = new regexp  
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = MyString
LastCount = -1
NeverEnds = 0
Do Until NeverEnds = 1
        Set objFile = objFSO.OpenTextFile(MyTextFile, 1)
        X = objFile.Readall
        Set myMatches = myRegExp.Execute(X)
        If LastCount = -1 Then
                Set LastCount = myMatches
        Else
                If myMatches.count > LastCount Then
                MsgBox "Yes"
                LastCount = myMatches
                        WScript.Quit
                End If
        End If
        objFile.Close
        WScript.Sleep 5000 ' sleep for 5 seconds
Loop
 User generated image
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial