LB Booster
« Opening the same RANDOM file twice »

Welcome Guest. Please Login or Register.
Jun 22nd, 2017, 4:35pm


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
LB Umbrella forum
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 373 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1190
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 »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls