[futurebasic] Re: [FB] Reading files... (Writing files is working)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2005 : Group Archive : Group : All Groups

From: Stu Cram <stu@...>
Date: Thu, 22 Dec 2005 19:30:20 -0600
Of course it isn't working. You haven't followed the examples sent to 
you carefully.

A)  This line will cause an error:
		PRINT #1, txt$
because it is trying to write to file number 1 which is not open. Maybe 
you want to just print the value of txt$ on the screen to check it: if 
so, then leave off the '#1,' part and write this instead.
		PRINT txt$

B)  Since you are using FILES$() to locate the file and get a filename, 
you must also include 'refNumVar%' in the OPEN instruction. Try 
changing this line...
		OPEN "I",2,fo1$
to...
		OPEN "I",2,fo1$,, refNumVar%
		
C) Be sure to DIM variable 'txt$' properly.

D) You realize that this will read just one line and show it in your 
edit field. If you continue reading more lines from the file, each of 
them will replace the contents of your edit field in turn. If what you 
want is to show all the lines of text in the edit field then you need 
to append each line to the edit field - check the help files for 
EDIT$() to see how to do this.

E) If you want to read several lines from your file but don't know for 
sure how many lines there are (likely), then you need a loop similar to 
this...
	OPEN "I", 2, .....
	WHILE NOT EOF( 2 )
		LINE INPUT #2,txt$
		EDIT$(_cEdit,......)  = txt$
	WEND
	CLOSE
	
F) Close the file as soon as you've read it.

G) Look more at the examples given you yesterday, today, and 1 1/2 
months ago. And the HELP files.

H) Be sure the file you 'created with my program' contains what it is 
expected to have. Open it in a word processor to check that out.

I) BTW:  You don't need to have the DEF OPEN instruction when reading a 
file; just when writing. For reading, it has no effect. Check the HELP 
file for more details. I would change it to DEF OPEN "TEXTttxt" while 
testing your program too to allow the file to be opened for checking in 
SimpleText, etc.

- Stu

==========================================================

On Dec 22, 2005, at 6:13 PM, <bheibert@...> wrote:

> I got this code to read files created with my program
>
> DIM fo1$
> DEF OPEN "HBSfHBas"
> fo1$ = FILES$(_fOpen,"HBSfHBAS","Open HBasic file...",refNumVar%)
> OPEN "I",2,fo1$
> LINE INPUT #2,txt$
> PRINT #1, txt$
> EDIT FIELD #_cEdit,txt$
>
> But it isn't working
>
> --
>
>