LB Booster
« Opening the same RANDOM file twice »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:34am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Opening the same RANDOM file twice  (Read 476 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Opening the same RANDOM file twice
« Thread started on: Jan 10th, 2015, 11:31am »

LB 4 allows you to have the same RANDOM file open twice (or more times) simultaneously, so long as you use a different handle each time. So you could for example do this:

Code:
    OPEN "test.dat" FOR random AS #file1 LEN = 123
    FIELD #file1...
    PUT #file1...
    OPEN "test.dat" FOR random AS #file2 LEN = 123
    FIELD #file2...
    PUT #file2...
    CLOSE #file1
    CLOSE #file2 

LBB however won't permit that: opening a file for output locks that file and it cannot be opened a second time (for update) until the first handle has been closed:

Code:
    OPEN "test.dat" FOR random AS #file1 LEN = 123
    FIELD #file1...
    PUT #file1...
    CLOSE #file1
    OPEN "test.dat" FOR random AS #file2 LEN = 123
    FIELD #file2...
    PUT #file2...
    CLOSE #file2 

Unfortunately if you try to run the first code example above in LBB the result is not an error message, but instead the second OPEN causes the file to be emptied (it tries to open the existing file, which fails, decides that the file therefore doesn't exist so creates a new one)! So what you end up with is an empty data file for no obvious reason.

Edit: I will arrange that in the next release of LBB you get an 'Access denied' error if you try to open a random file for update on two different handles simultaneously.

Richard.
« Last Edit: Jan 10th, 2015, 4:08pm by Richard Russell » 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