BBC BASIC for Windows
« Moving and array between programs »

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



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: Moving and array between programs  (Read 69 times)
chrispc
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx Re: Moving and array between programs
« Reply #10 on: Oct 27th, 2014, 10:37pm »

Thanks for your suggestions. I now respond as follows:

1. You say about statement 300: “Overhere GinFileNum% equals 0…”
What does “Overhere” mean? Does it mean on your system when you run the program?
Does that mean that when you run my program you don’t get the same result for the variable GinFileNum% that I get when I run the program? As my REMARK 310 said, I get 5; do you really get 0? If so, doesn’t that mean there is something seriously wrong with either your setup or with mine?

2. I am grateful for all the attention you have both paid to my problem, but I am now very confused, largely because I don’t know enough to understand all of your discussion. I have made some changes to my programs following (some of?) your suggestions, and have reached the following programs: Test File Handling10 has become Test File Handling12, and Test File Handling11 has become Test File Handling13. Can we please start again from those versions i.e. 11 and 13, which I copy below.

3. The last change I made, i.e. changing line 50 from

fnum=OPENIN(“GinFile”)

to

fnum=OPENIN(“GinFile.dat”)

made no difference to my result; I still got all Found(F)=0, as I explain in my statements 10 and 15.

I am sorry to be such a nuisance, but am comforted by seeing the experts finding it tricky too.

Thanks
chrispc
---------------------------------------------------------------
10 REM: THIS IS PROGRAM "TEST FILE HANDLING12".
30 REM: IT IS N.10 BUT WITH THE CHANGES [[unfinished !!]] SUGGESTED ONLINE BY RICHARD(g4bau) and Edja.
35 REM: I AM TESTING FILE HANDLING WITH THIS ONE-DIMENSIONAL FILE
40 REM: BEFORE TRYING TO USE IT WITH A 3-DIM FILE IN MY MAIN PROGRAM.
50
60 REM: I HAVE TRIED VARIOUS COMBINATIONS OF OPENOUT, OPENUP,
70 REM: OPENIN etc. and still cannot get it to work. Help please.
80 REM: Also see my program "TEST FILE HANDLING13" in which I try ro retrieve this file.
90 REM----------------------------------------------------
100
110 DIM GIN(12)
120
130 X=0
140 A=0
150 REPEAT
160 X=X+1
170 A=A+3
180 GIN(X)= A
190 PRINT"GIN(";X;") = ";GIN(X)
200 G$=GET$
210 UNTIL X=10
220 PRINT"GIN(X) PRINTING FINISHED"
230 REM: GIN(X) stands in for the already-created file N(X,Y,Z) in the program SUDOKU80.
240 REM---------------------------------------------------------------------------------
250 REM: NOW I WILL TRY TO SAVE THE FILE "GIN", AS "GinFile".
260 PRINT""
270 GinFileNum%= OPENOUT ("GinFile.dat")
280 REM: "GinFile" is the name I have given to my newly created file.
290 REM: GinFileNum% is my name for the number the computer has assigned to that new file.
300 PRINT"GinFileNum%= ";GinFileNum%
310 REM: This returns the channel number 5.
320 PRINT"AFTER OPENOUT GinFile"
330 M=0
340 L=OPENIN"GinFile.dat"
350 REPEAT
360 M=M+1
370
380
390 PRINT"M= ";M
400 UNTIL M=10
410 PRINT"PRINTING FINISHED"
420 END
==================================
10 REM: THIS IS TEST FILE HANDLING13, a change to TEST FILE HANDLING11; IN ST 50 I HAVE ADDED .dat AFTER ("GinFile
15 REM: BUT I STILL GET ALL Found(F)=0.
20 REM: I AM TRYING TO RETRIEVE THE FILE I TRIED TO SAVE IN PROGRAM "TEST FILE HANDLING12".
30 REM: THIS DOESN'T WORK. IT GIVES ALL Found(F) =0. What am I doing wrong?
40 DIM Found(20)
50 fnum = OPENIN("GinFile.dat")
60 PRINT"fnum = ";fnum
70 IF fnum=0 THEN PRINT "No GinFile data.":END
80
90 F=0
100 REPEAT
110 F=F+1
120 INPUT#fnum,Found(F)
130
140 PRINT "Found(";F;")= "; Found(F)
150 REM: THESE SHOULD BE MULTIPLES OF 3, BUT ALL=0. WHY??
160
170 UNTIL F=12
180 CLOSE#fnum
190 PRINT"INPUT FINISHED"
200 END
-========================-===========
====================================


User IP Logged

rtr2
Guest
xx Re: Moving and array between programs
« Reply #11 on: Oct 27th, 2014, 10:56pm »

on Oct 27th, 2014, 10:37pm, chrispc wrote:
I am sorry to be such a nuisance, but am comforted by seeing the experts finding it tricky too.

It is not in the least 'tricky'. I explained the problem, and its solution, in my replies. If you make the changes I suggested your program will work. Specifically:
  1. Delete line 340, which is spurious.
  2. Change line 380 to PRINT #GinFileNum%, GIN(M)
That is all you need to do.

Richard.
User IP Logged

chrispc
New Member
Image


member is offline

Avatar




PM


Posts: 19
xx Re: Moving and array between programs
« Reply #12 on: Oct 28th, 2014, 02:50am »

Thanks very much. That seems to work.
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: Moving and array between programs
« Reply #13 on: Oct 28th, 2014, 11:02am »

Quote:
You say about statement 300: “Overhere GinFileNum% equals 0…”
I've copied your program from your forum message and executed it without first saving it. As a result GinFileNum% equals 0. Nothing to do with your coding and entirely my error (see also Richard's explanation)
Quote:
changing line 50 from fnum=OPENIN(“GinFile”) to fnum=OPENIN(“GinFile.dat”) made no difference to my result
Yes it does.You've made this correction (before adding Richard's corrections) and it didn't work because in the first program you did create the file GinFile.dat but left it empty. When you then tried to read from it with your second program it executed correctly but without finding any data in the file. Therefore the values shown were all equal to zero.

Now that you've applied the corrections that Richard correctly suggested the first program does write to the file and the data that you read with the second program are no longer zero.

As a final check (only for your better understanding) replace line 50 fnum = OPENIN("GinFile.dat") again to 50 fnum = OPENIN("GinFile") but keep Richard's corrections in the first program. Then run both program's to see that the second one won't open the file anymore.

I hope this leads to a better understanding, certainly not adding to any confusion.

Eddy
User IP Logged

rtr2
Guest
xx Re: Moving and array between programs
« Reply #14 on: Oct 28th, 2014, 12:22pm »

on Oct 28th, 2014, 11:02am, Edja wrote:
As a final check (only for your better understanding) replace line 50 fnum = OPENIN("GinFile.dat") again to 50 fnum = OPENIN("GinFile") ... see that the second [program] won't open the file anymore.

I'm not keen on the idea of introducing a deliberate fault just to observe that it causes the program to fail. In any case the effect may not be what you describe - suppose one of the programs has been saved with the name 'GinFile' (i.e. as the file GinFile.bbc) or that a data file 'GinFile' has previously been created by an earlier version of the first program. Either way the modified code will open the file but it will report the wrong results!

Quote:
I hope this leads to a better understanding, certainly not adding to any confusion.

I fear it is more likely to confuse than to educate!

Richard.
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