exporting text file?

Nick
Nick

August 6th, 2009, 6:45 pm #1

is is possible to export/read a text file (or any other type of file) so that you can (for ex.) save a game i was hopeing to do something like this


num1 = 10
num2 = 22
num3 = 52
name$ = YOUR

'some magical line(s) of code that would save a file (name$).txt
'to a specified location on the hard Drive
'starting here:

PRINT "Hello, " name$;" 's numbers are:"

PRINT " "

PRINT num1, num2, num3

' END of file, and saved code here...


and end up with a YOUR.txt file on the HDD that when opens sais:


Hello, YOUR's numbers are:

102252



p.s. I know the code i given won't really work, i just forget at the top of my head the proper way to PRINT variables....


any thoughts/suggestions?
thxs!
Quote
Share

Anon
Anon

August 6th, 2009, 8:02 pm #2

* use 'OPEN "foo.txt" for OUTPUT AS #1' and PRINT #1, "foo"
Quote
Share

Joined: February 2nd, 2006, 10:38 pm

August 6th, 2009, 10:31 pm #3

is is possible to export/read a text file (or any other type of file) so that you can (for ex.) save a game i was hopeing to do something like this


num1 = 10
num2 = 22
num3 = 52
name$ = YOUR

'some magical line(s) of code that would save a file (name$).txt
'to a specified location on the hard Drive
'starting here:

PRINT "Hello, " name$;" 's numbers are:"

PRINT " "

PRINT num1, num2, num3

' END of file, and saved code here...


and end up with a YOUR.txt file on the HDD that when opens sais:


Hello, YOUR's numbers are:

102252



p.s. I know the code i given won't really work, i just forget at the top of my head the proper way to PRINT variables....


any thoughts/suggestions?
thxs!
First OPEN a file name to use that does not exist.

OPEN "MyData.TXT" FOR APPEND AS #1   ' FOR OUTPUT erases the file each time

Then you can WRITE a list of string or numerical data to the file:

WRITE #1,  num1, num2, num3, name$

Result in file:  10, 22, 52, "Nick"

CLOSE #1   'always close a file when done or changing to other modes

To read the file OPEN "MyData.TXT" FOR INPUT AS #1  'make sure file is not empty!

INPUT #1, num1, num2, num3, user$

You can then read the data in a loop for more than one line of data.

Also look up the LOF and  EOF functions.
Quote
Like
Share