• Please review our updated Terms and Rules here

Writing Text Files - Applesoft BASIC

WMH

Experienced Member
Joined
Dec 26, 2011
Messages
425
Location
Florida
I know, I have another thread about Applesoft BASIC right next to this one. But this question doesn't really fit there.

I've been trying for a while (unsuccessfully) to write some text files with Applesoft BASIC.

I'm using the DOS intercept character like this:

10 ? CHR$(4);"OPEN EXAMPLE"
20 ? CHR$(4);"WRITE EXAMPLE"
30 ? "THIS IS A TEST."
40 ? CHR$(4);"CLOSE EXAMPLE"

For some reason, DOS isn't intercepting the command on line 40, and the text file reads like this:

CLOSE EXAMPLE
4

I'm obviously doing something wrong...

Can I write line 40 differently? Is my entire method wrong?

Thanks,
WMH
 
Are you sure you need the semicolon after CHR$(4)? All the examples I have seen for file i/o omit the semicolons for the DOS command lines.
 
Are you sure you need the semicolon after CHR$(4)? All the examples I have seen for file i/o omit the semicolons for the DOS command lines.

In Applesoft BASIC, the semicolon is needed because you have to emit a Control-D character to signal DOS, then write the command to the output buffer. Normally you don't need it for DOS commands, but you need it in BASIC.

modem7 said:
Example here

Maybe try "PRINT" instead of "?" in case something funny is going on there.

Thanks for the example, I was using a listing of MAKE TEXT from the DOS 3.3 1980 Master to try to figure it out before.

I did try typing out PRINT, but ? and PRINT are converted into the same token in memory, so I don't think that's the problem. Maybe it was this line that I threw on the end to verify the file, but I doubt it.

50 ? CHR$(4);"OPEN EXAMPLE" : ? CHR$(4);"READ EXAMPLE" : GET F$ : ? F$ : ? CHR$(4);"CLOSE EXAMPLE"

I used that line to verify, and that's when I saw that the file was incorrect.
 
10 ? CHR$(4);"OPEN EXAMPLE"
20 ? CHR$(4);"WRITE EXAMPLE"
30 ? "THIS IS A TEST."
40 ? CHR$(4);"CLOSE EXAMPLE"

For some reason, DOS isn't intercepting the command on line 40, and the text file reads like this:

CLOSE EXAMPLE
4

The code looks fine.
But from the output, it looks like you may have an invisible character somewhere.
Retype the program carefully and it should work correctly.
 
Thanks for the help guys, it seems my problem was actually a mistake on my part.

Line 30 (see post #1) was actually written on the Apple II as follows:

30 ? CHR$(4);"THIS IS A TEST."

Oh well, I guess everyone makes dumb mistakes. I definitely make more then my fair share when it comes to computers... :)

Just so you know, the program in post #1 was just an example, my real program was much more complex and it was more difficult to find the problem.
 
Back
Top