BBC BASIC for Windows
Programming >> Database and Files >> Writing multiple variables to a file
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1381755409

Writing multiple variables to a file
Post by johnblack on Oct 14th, 2013, 12:56pm

I am trying to use this code to write multiple user inputs to a file:

A=OPENOUT "PlayerAttribute"
PRINT#A,PoneName$,PoneSkill%,PoneStrength%
CLOSE#A

If only takes in the PoneName$ variable and tends to make random workds out of my other variables (which are derived from random numbers.

Re: Writing multiple variables to a file
Post by admin on Oct 14th, 2013, 1:47pm

on Oct 14th, 2013, 12:56pm, johnblack wrote:
IIf only takes in the PoneName$ variable and tends to make random workds out of my other variables (which are derived from random numbers.

It's doing what it should, but you won't be able to read the (binary) numeric values in a text editor. If you read the values back in from the file it will work fine:

Code:
 A=OPENIN "PlayerAttribute"
 INPUT#A,PoneName$,PoneSkill%,PoneStrength%
 CLOSE#A 

If you specifically want to be able to read the numbers in something like WordPad or Word then you'll have to write them as strings:

Code:
 A=OPENOUT "PlayerAttribute"
 PRINT#A,PoneName$,STR$(PoneSkill%),STR$(PoneStrength%)
 CLOSE#A 

Incidentally I don't recommend omitting the file extension, because a '.BBC' extension will be added automatically and the resulting file could easily be mistaken for a program. Better to choose a more appropriate extension, e.g:

Code:
 A=OPENOUT "PlayerAttribute.dat" 

Richard.
Re: Writing multiple variables to a file
Post by johnblack on Oct 14th, 2013, 2:20pm

Awesome! Thank you for all your help. You have taught me all I already know about BBC basic through your manual, which is really very thorough.

I am developing a scheme of work for some year 8 students, if you want it when I am finished you are welcome to a copy.

Thanks for your help!