2

I'm writing a program in GW-BASIC. For some reasons, I have the following error :

"Numéro de fichier illégal en 4712"

which can be translated in english by,

" illegal file number in 4712"

Here is a part of my code :

51 Chemin$ = "T:\Basic\Calculs\" + NF$

52 ON ERROR GOTO 60
53 MKDIR Chemin$
54 END

... ( a lot of code not important to solve this problem :) )

4711 CHDIR Chemin$
4712 OPEN "Intdrcrc.doc" FOR APPEND AS #3
4712 PRINT #3,       "*---------------------------------------------------------------------------------------------------------------*"
4713 PRINT #3, USING "* Centre ##### \        \#######.### #######.### Intersect Droite Cercler                                       *";IC,NC$,XC#,YC#
4714 PRINT #3, USING "* Point  ##### \        \#######.### #######.### R=#######.###                                                  *";IP,NP$,XP#,YP#,R#
4715 PRINT #3, USING "* 1er Intersection  M1                                            #####  \        \ #######.###   #######.###   *";I1,N1$,XM1#,YM1#
4716 PRINT #3, USING "* 2e  Intersection  M2                                            #####  \        \ #######.###   #######.###   *";I2,N2$,XM2#,YM2#
4717 PRINT #3,       "*---------------------------------------------------------------------------------------------------------------*"
4718 CLOSE #3
4719 CHDIR "T:\Basic"

I had the same problem in previous lines, so I changed the # after "APPEND", but here, at the line 4712, changing the # doesn't solve the problem..

I hope I'm clear enough,

thank you very much for your suggestions !

:)

manny-
  • 129
  • 2
  • 10
  • Yes, the error-message says quite clearly what it needs. What is `Intdrcrc.doc`? Do you have that file at all? Is it in the same folder where you run your program? – Duck Dodgers Jan 10 '19 at 11:53
  • 1
    If the file number (numero de fichier) is illegal, try changing `#3` to `#99`. Maybe something else is using file number 3? You also have line 4712 written twice; GW-BASIC may not allow that. –  Jan 11 '19 at 02:34
  • Hi Chrono, changing #3 to #99 doesn't solve the problem, I still get the error "bad file number". Concerning the double line 4712, it was a mistake during the Copy/Paste. When I use CTRL+F to find if there is "#3" used somewhere else is the program, notepad says that it is only used there.. – manny- Jan 12 '19 at 11:48

4 Answers4

0

It seems the Intdrcrc.doc file does not exist (although I can't be sure about that without looking at the rest of your code).

What you can try is,

  • replace OPEN "Intdrcrc.doc" FOR APPEND AS #3 with OPEN "Intdrcrc.doc" FOR OUTPUT AS 3 and try if it gives an error. This is just to test of course. You should revert back to APPEND later. We want to see if the error is gone with OUTPUT. If so, it probably means, the file does not exist, as you expected it to.

Secondly, you need to implement some error-handling after the OPEN command.

What you can do is something like this,

 4710 ...
 4711 SHARED errorflag
 4712 OPEN "Intdrcrc.doc" FOR APPEND AS 1
 4713 IF errorflag <> 0 THEN
 4714   errorflag = 0
 4715   CLOSE
 4716   PRINT "File not found - press return to continue."
 4717   INPUT "", a$
 4718   EXIT SUB
 4719 END IF
4720 PRINT #3,       "*------------------------------------------*"
4721 ...

So that we may know, something more if an error happens.

Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43
  • Hi, the program is located in T:\Basic. When runing the program, it asks me to give a number (folder number). Then the programm creates a new folder located in " T:\Basic\Calculs. For example : T:\Basic\Calculs\12050. Then the program saves different .doc files (in this case it is named "Intdrcr.doc") in the folder created. Qbasic automatically creates the new file if it doesn't exist. In this case, the .doc file doesn't exist yet, so it should be created, however it gives me an error. – manny- Jan 10 '19 at 12:24
  • It really don't understand what the problem is, because few lines before, I used the same syntax to create another .doc file and it worked well.. I'll try what you said and keep you informed :) – manny- Jan 10 '19 at 12:25
  • So, i used the same code, expect instead of using "#3# i just wrote "3", i have no more errors. A file is created.. however, and here again i can't explain it, the file created is "crclcrd.doc" which should be created but at line 7182... it makes no sense.. The program is 717 lines long, i could send it to you in a private message if it may help you understand .. – manny- Jan 10 '19 at 13:05
  • Did you include after line 4712, that bit of code that I put in my answer? The problem is, we still don't know what happens after line 4712. If you add that bit of code, at least we could be sure what is or is not happening. The program may continue past the error and create other files, which doesn't solve the problem. Please test once with that bit of code included in your program. – Duck Dodgers Jan 10 '19 at 13:14
  • without the line "SHARED erroflag", i have the result on the other message – manny- Jan 10 '19 at 13:50
  • do you have gwbasic or qbasic? *"Result : in gwbasic cmd window it is written : "File not found - press return to continue""*, as in that case your question is also mistagged. – Duck Dodgers Jan 10 '19 at 14:26
  • oh.. my bad.. i'm using gwbasic.exe to run the .bas files . I wrote "qbasic" because i thought it is the name of the language I use in the .bas files which are run through the programm gwbasic.exe – manny- Jan 10 '19 at 14:37
0

So i wrote this :

4702 CHDIR Chemin$
4703 OPEN "Intdrcrc.doc" FOR APPEND AS 3
4704 IF errorflag <> 0 THEN
4705 errorflag = 0
4706 CLOSE
4707 PRINT "File not found - press return to continue"
4708 INPUT "", a$
4709 EXIT SUB
4710 END IF

4712 PRINT 3,       "*---------------------------------------------------------------------------------------------------------------*"
4713 PRINT 3, USING "* Centre ##### \        \#######.### #######.### Intersect Droite Cercler                                       *";IC,NC$,XC#,YC#
4714 PRINT 3, USING "* Point  ##### \        \#######.### #######.### R=#######.###                                                  *";IP,NP$,XP#,YP#,R#
4715 PRINT 3, USING "* 1er Intersection  M1                                            #####  \        \ #######.###   #######.###   *";I1,N1$,XM1#,YM1#
4716 PRINT 3, USING "* 2e  Intersection  M2                                            #####  \        \ #######.###   #######.###   *";I2,N2$,XM2#,YM2#
4717 PRINT 3,       "*---------------------------------------------------------------------------------------------------------------*"
4718 CLOSE 3
4719 CHDIR "T:\Basic"

Result : in gwbasic cmd window it is written : "File not found - press return to continue"

And then the file "intdrcrc.doc" is created. But it is empty, as if "PRINT 3" didn't work

manny-
  • 129
  • 2
  • 10
  • When the .doc file exists and i run the program again, it still writes "File not found - press return to continue". Moreover, i've just noticed than after pressing "return" on the keyboard, i have a syntax error at line 4709 – manny- Jan 10 '19 at 13:35
  • Specifying **EXIT SUB** in a program doesn't do anything if it is not in a subroutine.. – eoredson Feb 13 '19 at 05:02
0

Why not try:

4702 CHDIR Chemin$
4703 OPEN "Intdrcrc.doc" FOR OUTPUT AS #3
4712 PRINT #3, "*---------------------------------------------------------------------------------------------------------------*"
4713 PRINT #3, USING "* Centre ##### \        \#######.### #######.### Intersect Droite Cercler                                       *"; IC, NC$, XC#, YC#
4714 PRINT #3, USING "* Point  ##### \        \#######.### #######.### R=#######.###                                                  *"; IP, NP$, XP#, YP#, R#
4715 PRINT #3, USING "* 1er Intersection  M1                                            #####  \        \ #######.###   #######.###   *"; I1, N1$, XM1#, YM1#
4716 PRINT #3, USING "* 2e  Intersection  M2                                            #####  \        \ #######.###   #######.###   *"; I2, N2$, XM2#, YM2#
4717 PRINT #3, "*---------------------------------------------------------------------------------------------------------------*"
4718 CLOSE #3
eoredson
  • 1,167
  • 2
  • 14
  • 29
0

Is that 2nd line numbered as 4712 replacing the first one? If so, the program will try to print into file number #3 which was not opened.

4712 OPEN "Intdrcrc.doc" FOR APPEND AS #3
4712 PRINT #3,       "*---------------------------------------------------------------------------------------------------------------*"
Everton
  • 12,589
  • 9
  • 47
  • 59