fileiobasicfreebasic

Why is my file deleting itself when I open it?


I’m currently learning BASIC (I use FreeBASIC) and I’m trying to open files. However, instead of opening files, my program deletes them. This is my code:

Dim f as Integer

f = FreeFile

Open "myfile" For Input Access Read As #f
If Err > 0 Then Print "Error opening the file. Error code:" ; Err : End

Close #f
End

When executing the code, myfile vanishes, the Error opening the file message prints and the error code is 0.

I tried with and without Access Read; and I tried different other things than Input (I tried Binary and Random for instance). I also tried another dialect (-lang fblite). None of this fixes the problem.

What am I doing wrong?

Some more infos:


Solution

  • The problem was that the file was named main.c and the BASIC file was named main.bas