ken bohnenkamp
12th January 2003, 21:05
I am reading in an ascii text file and writing each record to a Baan table. The last record of the ascii text file contains a CTL Z. This I assume marks the end of the file. This record I do not want to write to my Baan table. Can someone tell me the condition to check for so I don't write this control Z record.
if data.in = "ctl Z" doesn't seem to work. I guess I need to be checking for some hex or decimal values.
dnnslbrwn
12th January 2003, 22:14
If you were to try:
if strip$(data.in) = chr$(26) then ...
that should work.
Cheers,
-Dennis
PS: I added the strip$ without thinking as I normally use it when testing strings. Keep or remove as required
NPRao
12th January 2003, 23:54
You can use the tools function - seq.gets() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_seq_gets)
You can use different modes -
mode
Use this optional argument to specify the read mode for seq.gets(). Possible values are:
GETS_NORMAL
The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.
If the buffer is full, any remaining characters on the line being read are discarded.
This is the default mode.
GETS_ALL_CHARS
The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.
If the buffer is full, the next seq.gets() call starts reading at the point where the current seq.gets() finished. The use of this mode ensures that all characters available in input file are eventually returned.
GETS_SKIP_ALL
This is the same as GETS_NORMAL, except that if the last line in the file does not end with a new line character, that line is discarded completely and EOF is returned.
A sample code -
fp = seq.open(filename, "r")
if fp < 0 then
message("File Handling Errors")
exit(1)
endif
e = seq.gets(buffer, 1024, fp)
while not seq.gets(buffer, 1024, fp)
do.something(...)
endwhile
e = seq.close(fp)