open and read commands
Laura Brody
laura at hvcomputer.com
Sat Dec 1 16:59:55 PST 2007
Quoting Mike Fedkiw <filepro at adelphia.net>:
> filepro 5.0.09
>
> I need to open a .txt file and read each line so I can compare to an
> existing filepro file.
>
> does anyone have an example of the syntax for the open and read
> commands. I cant get past two lines of code without a syntax error.
>
> This is what I have. Syntax error at "open"
>
> aa="c:/jpgfile.wri"
> - - - - -
>
> bb=open(aa,r)
>
Here is the READLINE entry from "Laura's QRG and Help Files
for filePro v5.0" product:
@@@ READLINE()
v4.5 \r n = READLINE(handle,f [,n] ) \r - Read text from a file up to a
newline character. The second parameter is the field to store
the data. The optional third parameter limits the number
of characters read. If a newline is not encountered, the
field will be filled. If the field parameter was not defined
with a length and the third parameter omitted, the length of
the last assignment will be used. The return value is the
number of bytes copied into the field.
Note: The file must be opened in text mode.
Examples:
then: declare local handle(8,.0); declare local buf(200,*)
then: handle = open("/tmp/myfile.dat","rt")
if: handle le "0" ' Open failed.
then: end
if: ' "buf" will contain 99 or fewer characters.
then: x = READLINE(handle,buf,"99") ' x will contain 99 or less.
if: ' "buf" will contain 200 or fewer characters.
then: x = READLINE(handle,buf) ' x will contain 200 or less.
See also: CREATE(), OPEN(), READ(), WRITE(), WRITELINE()
You really want this:
declare local handle(8,.0)
declare local txt
aa="c:/jpgfile.wri"
handle = open(aa,"rt") 'notice that it is "rt" and not just r
if handle le "0"
then errorbox "Unable to open file:" < aa; exit
i = "160" 'how many characters will there be in a line and double it
x = readline(handle,txt,i)
if x eq "o" 'EOF reached
then x = close(handle)
'otherwise, do whatever you want with the text in variable txt
Does this help?
--
Laura Brody
+------------- Hudson Valley Computer Associates, Inc ----------+
| PO Box 859 120 Sixth Street http://www.hvcomputer.com |
| Verplanck, NY 10596-0859 Voice mail: (914) 739-5004 |
+------ PC repair locally, filePro programming globally --------+
More information about the Filepro-list
mailing list