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.Fi leSystemOb ject")
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(MyText File, 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
But at line 16 being If LastCount = -1 Then , i get an error, see attachment
MyString = "hello"
MyTextFile = "C:\Documents and Settings\admhomaa\Desktop\
Set objFSO = CreateObject("Scripting.Fi
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(MyText
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.