Hi,
I am trying to read a text file line by line and match the start of a line of text in the file. Once this matches I want to read the whole line then see if it matches what I require. Code below:
backuplinestart=" Exit code"
backupline=" Exit code = 0 (No error, Successful operation)"
count=2
handle = FileOpen(Dailylog, "READ")
while @TRUE ; Loop till break do us end
line = FileRead(handle)
lineshort=StrFix(line,"",10)
strmarker=StrCmp(backuplinestart,lineshort)
If strmarker==0 then strmarker1=StrCmp(backupline,line)
If (strmarker1==-1 || strmarker1==1) then count=count + 2
If line == "*EOF*" Then Break
endwhile
but when running it I am getting uninitialsed variable or undefined function strmarker1. Can anyone point out what is wrong in my code, I can't see it for looking now?
Thanks
Geoff
If line=="*EOF*" Then Break
Your code may actually be working, but without exiting the read loop you are trying to process the end of file marker and your variables are going haywire. Just a guess, but maybe move it to the start of the loop.
Thanks for your reply. I need to keep in the loop as the file I am reading has several lines that I need to find and analyse the comparison result for each of the lines.
Unless I'm blind you never initialize strmarker1 before trying to use it in your "IF" statement.
Set it to an appropriate value at the beginning of your script.
Jim
Quote from: JTaylor on October 13, 2014, 06:22:45 AM
Unless I'm blind you never initialize strmarker1 before trying to use it in your "IF" statement.
Set it to an appropriate value at the beginning of your script.
Jim
Comment 1:
The indentation in the OP suggests that he meant to have the line that checks stmarker1 only be executed if the previous IF was true (such that stmarker1 would thus be set). So, like:
If strmarker==0
strmarker1=StrCmp(backupline,line)
If (strmarker1==-1 || strmarker1==1) then count=count + 2
ENDIF
Comment 2:
I'm pretty sure that you should be testing for *EOF* at the top of the loop, not at the end (as Stan suggests).
Whenever I read a text file, I always use udsAssign(). So, iike:
#DefineSubroutine udsAssign(val,var)
%var% = val
Return val
#EndSubroutine ; udsAssign(val,var)
fh = FileOpen(Param1,"READ")
WHILE udsAssign(FileRead(fh),"Line") != "*EOF*"
...
ENDWHILE
Trust me; once you start using udsAssign(), you'll won't believe you ever lived without it.
Hi,
thanks for all the help and suggestions. I solved the issue by doing the below:
;Read daily backup log to see completion status of backup
handle = FileOpen(Dailylog, "READ")
while @TRUE ; Loop till break do us end
line = FileRead(handle)
lineshort=StrFix(line,"",10)
strmarker=StrCmp(backuplinestart,lineshort) ;Look for Exit code lines
If strmarker==0 then
handle1 = FileOpen(Exitcodelog, "APPEND")
FileWrite(handle1, line) ;Write Exit Code lines to temp work file
FileClose(handle1)
EndIf
If line == "*EOF*" Then Break
endwhile
FileClose(handle)
Geoff