BBC BASIC for Windows
« File Problems! »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:15pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: File Problems!  (Read 612 times)
samconran
New Member
Image


member is offline

Avatar




PM


Posts: 2
xx File Problems!
« Thread started on: Dec 11th, 2013, 10:59am »

Hey guys,

Can anyone help me with this, please? So I want to set up a game where a number of characters (up to 4) play a game. At the start of the game some dice are thrown and one score is divided by another and added to ten. I want to store the data in a file but I don't know how to reopen a file and put in new information. So I want to store some data, close the file and then be able to open it and add more without deleting the original content. My code is below. Please help!

Thanks, Sam :)


Code:
      
      INPUT "Enter filename: " filename$
      
      INPUT "Enter number of players: " plays%
      
      FOR times%=1 TO plays%
        
        filename$ = filename$ + ".txt"
        
        filenum = OPENOUT(filename$)
        
        
        INPUT "Enter character's name: " c$

        
        strength1% = 10
        skill1% = 10
        
        strength2% = strength1%+(RND(12)/RND(4))
        skill2% = skill1%+(RND(12)/RND(4))

        
        PRINT ""
        PRINT ""
        PRINT c$ "'s strength is: "; strength2%
        PRINT ""
        PRINT c$ "'s skill is: "; skill2%
        
        

        
        PRINT#filenum, c$ + "'s strength is: " + STR$(strength2%)
        
        PRINT#filenum, c$ + "'s skill is: " + STR$(skill2%)
        
        
        
        
        CLOSE#filenum
        
        
        
      NEXT times%
      END
      
      
      CLOSE#filenum
 
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: File Problems!
« Reply #1 on: Dec 11th, 2013, 12:06pm »

on Dec 11th, 2013, 10:59am, samconran wrote:
So I want to store some data, close the file and then be able to open it and add more without deleting the original content.

To append data to an existing file, open it (OPENUP) then move the pointer to the end (PTR#file% = EXT#file%). If you want to deal with the initial case when the file doesn't exist, try OPENUP first and if that fails use OPENOUT:

Code:
      file% = OPENUP(filename$)
      IF file%=0 THEN file% = OPENOUT(filename$)
      PTR#file% = EXT#file% 

Richard.
User IP Logged

samconran
New Member
Image


member is offline

Avatar




PM


Posts: 2
xx Re: File Problems!
« Reply #2 on: Dec 11th, 2013, 1:43pm »

Okay thanks very much! I'll try and impliment that when I get the chance.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls