LB Booster
Programming >> Compatibility with LB4 >> Opening the same RANDOM file twice
http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1420893066

Opening the same RANDOM file twice
Post by Richard Russell 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.