Hi Everyone,
I'm editing this code in notepad so unfortunately, I don't have much tools to work with. I'm getting a type mismatch error and I understand where the problem is but I'm not sure how to fix it. Any help would be much appreciated.
The function below opens up a log file and reads each line for keywords of "Error" or "Warning". If it finds it, then it sends an email. We found that this functions works great except that we run this every 15 minutes to check the log file. We realized that the code will send emails for all "Error" or "Warning" found within the log even on those found 15 minutes ago. So I added some coding based on the structure of the log file. Basically compare the time stamp of each line to the current time and if its within 15 minutes then send the email, if not ignore it.
Here's a sample of the log data in this example assume the time is 10:15. The log captures the data in military time.
2006-05-05 11:21:26.136 : Record Not Found: S7_506 failed scanner: 522 HU:
.
2006-05-15 9:00:26.136 : Error Should Not Find: S7_506 failed scanner: 522 HU:
.
2006-05-15 10:05:26.136 : Error Should Find 1: S7_506 failed scanner: 522 HU:
.
2006-05-15 10:05:26.136 : Error Should Find 2: S7_506 failed scanner: 522 HU:
.
I'm editing this code in notepad so unfortunately, I don't have much tools to work with. I'm getting a type mismatch error and I understand where the problem is but I'm not sure how to fix it. Any help would be much appreciated.
The function below opens up a log file and reads each line for keywords of "Error" or "Warning". If it finds it, then it sends an email. We found that this functions works great except that we run this every 15 minutes to check the log file. We realized that the code will send emails for all "Error" or "Warning" found within the log even on those found 15 minutes ago. So I added some coding based on the structure of the log file. Basically compare the time stamp of each line to the current time and if its within 15 minutes then send the email, if not ignore it.
Here's a sample of the log data in this example assume the time is 10:15. The log captures the data in military time.
2006-05-05 11:21:26.136 : Record Not Found: S7_506 failed scanner: 522 HU:
.
2006-05-15 9:00:26.136 : Error Should Not Find: S7_506 failed scanner: 522 HU:
.
2006-05-15 10:05:26.136 : Error Should Find 1: S7_506 failed scanner: 522 HU:
.
2006-05-15 10:05:26.136 : Error Should Find 2: S7_506 failed scanner: 522 HU:
.
Code:
Function checkLogs(currFlagShiplog)
Dim fso, f1, ts, s, notifyString
Dim hn, mn, hb, mb 'hn = hournow, hb = hour before, etc
Const ForReading = 1
notifyString = ""
Set fso = CreateObject("Scripting.FileSystemObject")
' Read the contents of the file.
Set ts = fso.OpenTextFile(currFlagShiplog, ForReading)
hn = left(right(now,11),2)
mn = mid(right(now,11),4,2)
Do While ts.AtEndOfStream <> True
s = ts.ReadLine
hb = mid(s,12,2)
mb = mid(s,15,2)
if (hn - hb) <> 0 then
'[COLOR=#ff0000] Type mismatched error with hn - hb because different data type. I've tried dim hn, hb as integer and it won't take it. [/color]
else
if (mn - mb) >= 15 then
'[COLOR=#ff0000]Same error here[/color]
else
if s = " ." then
else
if Instr(s,"Warning") <> 0 or Instr(S, "Error") <> 0 then
notifyString = s
else
End if
End if
If notifyString <> "" Then
notifyIT(notifyString)
notifyString = ""
Else
End if
end if
end if
Loop
ts.Close
Set ts = nothing
Set fso = nothing
End Function