io - Why is my file deleting itself when I open it? - Stack Overflow

I’m currently learning BASIC (I use FreeBASIC) and I’m trying to open files. However, instead of openin

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:

  • Compiler: FreeBASIC version 1.10.1 (2024-01-06)
  • OS: Arch GNU/Linux (kernel version 6.13.5)

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:

  • Compiler: FreeBASIC version 1.10.1 (2024-01-06)
  • OS: Arch GNU/Linux (kernel version 6.13.5)
Share Improve this question asked Mar 12 at 14:00 Jean DuboisJean Dubois 211 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

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

The code you wrote has the correct syntax and mode, the fact that in your case the file "myfile" disappears is due to some error on the media or from the program that creates it, so check elsewhere because the code is correct, I tested it and with the FreeBASIC 1.10 version it works correctly.

Dim f as Integer 'init the f like a var integer

f = FreeFile ' set the value of f the first free number file available

Open "myfile" For Input Access Read As #f ' open in read only mode the file myfile
If Err > 0 Then ' verify any error and show the number closing the program
    Print "Error opening the file. Error code:" ; Err 
    End
else 
    print "File opened and exist OK"
end if
Close #f ' close the file

End

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744748595a4591456.html

相关推荐

  • io - Why is my file deleting itself when I open it? - Stack Overflow

    I’m currently learning BASIC (I use FreeBASIC) and I’m trying to open files. However, instead of openin

    5天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信