I am trying to create a script that reads the contents of a file and reacts to certain error messages. So far everything is working as intended; however, I cannot get the 'If' statement to perform any action. It is intended to read the file and if a error message occurs within the text document, it will just completely taskill the Script. Here is a sample of what I have so far:
Dim WshShell, objfso, LogData, oShell
Const ForReading = 1
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objPL = objfso.OpenTextFile("C:\-----", ForReading)
Set oShell = WScript.CreateObject("WScript.Shell")
error = "Invalid"
LogData = objPL.ReadAll
Sub CheckTextFile
Do Until objPL.AtEndOfStream
If InStr(1, LogData, error) > 0 Then
objPL.Close
oShell.AppActivate "taskkill /F /IM WScript.exe"
WScript.Sleep 2000
End If
Loop
End Sub
----- Also you can assume that in my code I already have a text document created with output stating that there is errors that say "Invalid". It seems that anything within my If statement is ignored and skipped. No actions are ever performed from the If statements.
LogDatais after theReadAllbecause you have not declared/explicitly typed it. It may not be what you assume it is. It would also be helpful to know if you have debugged the results of theReadAllto confirm that the contents are what you think they are.