Unable to use file commands in v6

Just starting out? Need help? Post your questions and find answers here.
TwilCynder
New User
New User
Posts: 2
Joined: Wed Dec 04, 2024 4:00 pm

Unable to use file commands in v6

Post by TwilCynder »

Hello ! Been using PB 5.72 until recently, and after upgrading I've been having a weird issue : I can't open files at all.

OpenFile and Reafile will always return a non-null value, regardless of whether the file exists, and then any file-reading function (including Eof) will crash with "The specified #File is not initialized".
This is happening with all versions starting with 6.0.0, same code works fine in 5.72, and tested on multiple computers, including one where all installs are fresh.

Is there something I'm missing ?

Code example I tested with just in case, but this happens with my existing projects as well

Code: Select all

file.l = OpenFile(#PB_Any, "C:\msys64\ucrt64.ini") ; Using this file because it was the first very short path that came to mind, tested with other various files
Debug file ;will always display a non-null value
If Not file
  Debug "404"
  End
Endif

ReadString(file, #PB_UTF8, 20) ;Will crash here, apparently the file is not initialized ; tested with other functions, including Eof
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Unable to use file commands in v6

Post by Quin »

The problem is that you're storing the value in a long, not an integer. If you're on 64-bit, the value is most likely larger than can fit in a long. Change it to .i and all should work as expected.
TwilCynder
New User
New User
Posts: 2
Joined: Wed Dec 04, 2024 4:00 pm

Re: Unable to use file commands in v6

Post by TwilCynder »

Thank you, that was indeed it ! No idea why I decided to use longs for file handles in the first place now that I think about it
User avatar
Kiffi
Addict
Addict
Posts: 1509
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Unable to use file commands in v6

Post by Kiffi »

Additional tip: If you only want to read from a file, it is better to use ReadFile().
Hygge
Post Reply