Menu

how do I save to file please

Anonymous
2016-11-20
2016-12-06
  • Anonymous

    Anonymous - 2016-11-20

    Please help. I write sports programs for my own amusement. But what I can't do and I know I never will do is be able write to file. What I mean is that if I play say, my cricket game but haven't time to conclude it so I have to turn off and restart the next day, all my variables are at their original values and Boycott's near century - is lost. He's got to start at 0 again. I want him to be able to continue from where he left off

    Rob has kindly tried to help me but I just don't get it. I've tried lots of examples from lots of books and programs - but just don't get it

    Please could some in a sympathetic and simple way point me in the right direction. I code something into the program - but what! And simple is a most important word as I've got no understanding of the theory as the hours and hours I've spent trying to solve it myself goes to show

    thanks!

    Eric Walter
    Liverpool

     
  • Anonymous

    Anonymous - 2016-11-21

    A simple program that writes to file and reads from file would look something like this:

    10 INPUT "Enter the score", SCORE
    15 REM write the score to file
    20 OPEN "SCORE.DAT" FOR OUTPUT AS 1
    30 PRINT#1, SCORE
    40 CLOSE 1
    45 REM read the score back
    50 OPEN "SCORE.DAT" FOR INPUT AS 1
    60 INPUT#1, S
    70 CLOSE 1
    80 PRINT "The score was: ", S
    
     
  • Anonymous

    Anonymous - 2016-11-22

    Hi Anonymous!

    Thanks very much for taking the time to reply - most grateful

    I like your poems too!

    Eric Walter
    Liverpool

     
  • Anonymous

    Anonymous - 2016-11-30

    I'm still stuck. My basic problem is that I've got no insight of how things work. What I want to do is to change an initial data value so that when I turn the program off, when I next load it and run it, the changed value is now the opening value. I've tried to achieve this in adding to Anon's help. Here I generate a list of 10 random numbers, decide to change the value of s(3) but it could be any. I change it, save the listing, turn it off - but when I run it again, the original value for s(3) still appears.

    As always I'd be most gratefulfor any help

    Eric Walter
    Liverpool

    8 REM cook
    10 DIM S(10):FOR F=1 TO 10:READ S(F):NEXT
    50 FOR F=1 TO 10:S(F)=INT(RND*100):PRINT F;" ";S(F):NEXT

    110 INPUT "Enter the score", S(3)
    115 REM write the score to file
    120 OPEN "S.DAT" FOR OUTPUT AS 1
    130 PRINT#1, S(3)
    140 CLOSE 1
    145 REM read the score back
    150 OPEN "S.DAT" FOR INPUT AS 1
    160 INPUT#1, S
    170 CLOSE 1
    180 PRINT "The score was: ", S(3)
    200 FOR F=1 TO 10:PRINT S(F):NEXT
    900 SAVE"cook.bas",A
    999 STOP
    1000 DATA 0,0,0,0,0,0,0,0,0,0
    9000 REM

     
  • Anonymous

    Anonymous - 2016-12-05

    I think there are two main issues here: First, in line 160 you're reading the value into the scalar variable S. The array element S(3) is unchanged by that, so whne you next print it, it will still hold the value put in there originally and print it in line 180.

    Second, even if that is fixed, this program does not distinguish between a writing run and a reading run. Whenever is executed, it will ask for a score, write that value into a file, read the same value back and show it.

    To achieve what you want, you could put the reading and writing of the file into different subroutines and call one or the other depending on user input. For example, ask the user whether he wants to use the previous value or use the stored one. If the latter, call the subroutine to read the value from file; if the former, get the value from an INPUT statement and write it to file.

     
  • Anonymous

    Anonymous - 2016-12-05

    try these , in google search , INVENTORY SYSTEM IN GW-BASIC, and youn will find something as you want, modify it and use it.

     
  • Anonymous

    Anonymous - 2017-02-24

    I have just discovered PC-Basic and really,really want to use it. I have a large program written in GWBASIC that it tried to run under PC-Basic. The calculations were fine and the graphs were fine even though I'm using Win 7 64 bit. But disk handling does not work. Even the simple file uses as an example earlier does not work. The screen goes black for a split second then back to the previous background.
    10 INPUT "Enter the score", SCORE
    15 REM write the score to file
    20 OPEN "SCORE.DAT" FOR OUTPUT AS 1
    30 PRINT#1, SCORE
    40 CLOSE 1
    45 REM read the score back
    50 OPEN "SCORE.DAT" FOR INPUT AS 1
    60 INPUT#1, S
    70 CLOSE 1
    80 PRINT "The score was: ", S

     
    • Rob Hagemans

      Rob Hagemans - 2017-03-05

      I'm sorry, but I can't reproduce this issue. On PC-BASIC 15.08.11 on WIndows 7 64-bit the program works for me as expected (see screenshot attached).

      • Does the problem only happen when a program tries to access the disk?

      • Could you describe in more detail what you mean by "The screen goes black for a split second then back to the previous background" - does the PC-BASIC window disappear from the screen and the taskbar? Does the whole screen go black or just the PC-BASIC window? With 'previous background' do you mean the Windows desktop?

      Thanks
      Rob

       
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.