[comp.sys.apple2] More BASIC programs

apollo@pro-hindugods.cts.com (System Administrator) (06/27/91)

I have another BASIC problem I need help with.  I'd also like to thank the
two who helped me out with my VAL problem.  It works just great now. 
Thanks guys.

Ok, now this problem.  What I need to do is have my program remove the
present contents of a text file, which is only one line and contains very few
characters, then replace that line with a new string of charaters.  Like this:

10 REM Another BASIC problem
20 TS$ = "/hd.1/test"
30 PRINT D$"DELETE "TS$:REM That deletes the file just fine...now...
40 PRINT D$"OPEN "TS$:PRINT D$"APPEND "TS$:PRINT TEXT$:PRINT D$"CLOSE "TS$

What that gives me is a syntax error.  I realise this much...there is no
longer a file "hd.1/test" after it is deleted and the program cannot open a
file that does not exist.  So, my question...how do I recreate the file...or
better yet, how do I delete ONLY the first line of the file "test?"

This is what TEST has:

user.m

Now, I want the program to open TEST, remove that ONE line, and then add the
new one stored in variable TEXT$.  How do I do that is my question, or do I
just have to delete the whole file, and then recreate it?  Either way, I can
get along.  Just help me get the easiest possible way.  Thanks guys.

Amrit

===The Hindu Love Gods BBS - - - - Bloomfield Hills, MI - - - -313/644-0481===
ProLine:  apollo@pro-hindugods                | Amrit S. Chauhan
Internet: apollo@pro-hindugods.cts.com        | Voice: 313/644-2971
UUCP:     crash!pro-hindugods!apollo          | Intel 9600ex Modem in use.
ARPA:     crash!pro-hindugods!apollo@nosc.mil | PPE member: thanks jwolverton
-------------------------------------------------------------------------------
The only ProLine site in the 313 area.  Come on, someone buy a ProLine here.
:)  :-)  C:#  %-|   =|:-)=  :<)=  `-)  :-C  :-O  :-D  B-)  8-:)  :->  :-c  :*)
===============================================================================

curtis@achilles.ctd.anl.gov (Jeffrey Curtis ) (06/27/91)

In article <1991Jun27.003549.3197@clark.edu> apollo@pro-hindugods.cts.com (System Administrator) writes:
>Ok, now this problem.  What I need to do is have my program remove the
>present contents of a text file, which is only one line and contains very few
>characters, then replace that line with a new string of charaters.  Like this:
>
>10 REM Another BASIC problem
>20 TS$ = "/hd.1/test"
>30 PRINT D$"DELETE "TS$:REM That deletes the file just fine...now...
>40 PRINT D$"OPEN "TS$:PRINT D$"APPEND "TS$:PRINT TEXT$:PRINT D$"CLOSE "TS$
>
>What that gives me is a syntax error.  I realise this much...there is no
>longer a file "hd.1/test" after it is deleted and the program cannot open a
>file that does not exist.  So, my question...how do I recreate the file...or
>better yet, how do I delete ONLY the first line of the file "test?"

	No, "OPEN" under both DOS 3.3 and ProDOS will create the file if it
doesn't exist.  What you might be having a problem with is the "APPEND"
rather than "WRITE".  Since you know the file is blank, there's no need to
have an APPEND.  Try it the other way.  If that doesn't work, separate line
40 into all of its components on different lines and see where the error
occurs.

	Actually, now that I look at it, if that's EXACTLY your program, the
problem is that "TEXT" in an AppleSoft reserved word and can't be used in
a variable situation.  If you list the program, it will actually print out as

40 PRINT D$"OPEN "TS$ : PRINT D$"APPEND "TS$ : PRINT  TEXT  $ : PRINT D$....

which should tip you off to that fact.

*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
+ Jeffrey S. Curtis (708)972-8585 B41801 AT ANLVM curtis@achilles.ctd.anl.gov +
*        Computing and Telecommunications, Argonne National Laboratory 	      *
+ Want a free copy of Heatseeker, the Apple's fastest disk utility?  Mail me! +
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*

drudman@hpcc01.HP.COM (Drew Rudman) (06/27/91)

If all you are storing in the file is one string, you can simply open the file
and write to the beginning of it.  Use the following code:

	10 PRINT CHR$(4)"OPEN ";FILE$
	20 PRINT CHR$(4)"WRITE ";FILE$
	30 PRINT USER$
	40 PRINT CHR$(4)"CLOSE ";FILE$

this will store the variable USER$ into the file FILE$.  To read back the
value, use:

	10 PRINT CHR$(4)"OPEN ";FILE$
	20 PRINT CHR$(4)"READ ";FILE$
	30 INPUT USER$
	40 PRINT CHR$(4)"CLOSE ";FILE$

This will read the value out of the file FILE$ and put it into variable USER$.

Everytime you use the first procedure with a different value in variable USER$,
it will overwtie the previous value in the file, and a subsequent call to the
second procedure will retrieve the most recent USER$ that was written out.

There is no need to delete the file FILE$ everytime you want to store off a new
USER$.

[ Call...              9600bps/60meg ][ Drew Rudman                          ]
[            The Charge              ][                                      ]
[   Apple ][              IBM        ][ Internet: drudman@hpiosa.corp.hp.com ]
[          (415) 321-4713            ][ The Charge BBS: Axe Slinger (#1)     ]

fadden@uts.amdahl.com (Andrew T. McFadden) (06/29/91)

In article <1991Jun27.003549.3197@clark.edu> apollo@pro-hindugods.cts.com (System Administrator) writes:
>40 PRINT D$"OPEN "TS$:PRINT D$"APPEND "TS$:PRINT TEXT$:PRINT D$"CLOSE "TS$
                                                  ^^^^
>What that gives me is a syntax error.

Try typing the followng:
10 ABCD$ = "foo"
20 TEXT$ = "bar"
30 TOAD$ = "garp"

You should notice a slight difference in the spacing.  That's because "TEXT"
and "TO" are reserved words in Applesoft, and therefore cannot be part of
a variable name.

[ description of other stuff deleted ]

If it gives you a "?SYNTAX ERROR", then the problem is with what you typed,
not with what the program is doing.

>Amrit

-- 
fadden@uts.amdahl.com (Andy McFadden)