OpenSeq "C:\FileTest\Test.txt" To MyFile
Then
Call DSLogInfo("MB Successfuly Opened File","FileTest")
WriteSeq "First Line" to MyFile
Then
WeofSeq MyFile
Call DSLogInfo("MB Success Writing To File":Status(),"FileTest")
CloseSeq MyFile
Ans = 0
End
Else
Call DSLogInfo("MB Error Writing To File, status = ":Status(),"FileTest")
Call DSLogFatal("MB Error Writing To File","FileTest")
GoTo ErrExit
End
End
Else
Call DSLogWarn("MB Error Opening File, status ":Status(),"FileTest")
ErrExit:
CloseSeq MyFile
Ans = 1
End
But it is not appending the text,
As suggested in the Developer's Guide, I am writing the WeofSeq immediately, which shifts the pointer to next line.
The WEOFSEQ writes an EOF (end-of-file) at the current location, truncating the file. And your WRITESEQ statement won't work the way you expect it either, as the file pointer is at the beginning of the file after you open it.
I tried to use this modified code , to shift the pointer to new line and continue writing... but now the loop exits at encountering the EOF and does not go to WriteFile...
OpenSeq "C:\FileTest\Test.txt" To MyFile
Then
Call DSLogInfo("MB Successfuly Opened File","FileTest")
ReadSeq Dummy From MyFile
Then
LOOP
WHILE Status() ne 1
ReadSeq Dummy From MyFile
UNTIL ( Status() ne 1 )
REPEAT
Call DSLogInfo("MB Reached EOF, status ":Status(),"FileTest")
Goto WriteFile
End
Else
Call DSLogWarn("MB Error Reading 1 File, status ":Status(),"FileTest")
Goto ErrExit
End
LOOP
WHILE Status() ne 1
ReadSeq Dummy From MyFile Else Goto ErrReading;
UNTIL ( Status() ne 1 )
REPEAT
Call DSLogInfo("MB Reached EOF, status ":Status(),"FileTest")
Goto WriteFile
ErrReading:
Call DSLogWarn("MB Error Reading File, status ":Status(),"FileTest")
Goto ErrExit
WriteFile:
WriteSeq InputText to MyFile
Then
WeofSeq MyFile
Call DSLogInfo("MB Success Writing EOF To File":Status(),"FileTest")
Call DSLogInfo("MB Success Writing To File":Status(),"FileTest")
CloseSeq MyFile
Ans = 0
End
Else
Call DSLogInfo("MB Error Writing To File, status = ":Status(),"FileTest")
Call DSLogFatal("MB Error Writing To File","FileTest")
GoTo ErrExit
End
End
Else
Call DSLogWarn("MB Error Opening File, status ":Status(),"FileTest")
ErrExit:
CloseSeq MyFile
Ans = 1
End
Seems that you took an issue with a simple solution - the change that Arnd posted - and made things way more complicated than they need to be. You just needed his one command to reset the file pointer to the EOF so you could append, there's no need to read all of the records to get there.
How about spelling out - in words - what this routine is supposed to do.
-craig
"You can never have too many knives" -- Logan Nine Fingers