LB Booster
« handle variable with files »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:53am



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: handle variable with files  (Read 435 times)
wscbill
New Member
Image


member is offline

Avatar




PM


Posts: 2
xx handle variable with files
« Thread started on: May 17th, 2017, 5:32pm »

Getting the "handle used for incompatible devices" error in LBB when using a handle variable for files. Works successfully in LB.

The situation involves opening an unknown number of files, some of which may need to be open concurrently.

The troubleshooting write-up indicates this error occurs when the same handle is used for file and window, etc. Only files used here.

Some example code that generates the error.

Code:
    fn = fn+1
    hvar$ = "#B" + str$(fn)
    print hvar$
    open "errors1.txt" for input as #hvar$
    line input #hvar$, s$ 
    print s$
    close #hvar$

    fn = fn+1
    hvar$ = "#B" + str$(fn)
    print hvar$
    open "errors2.txt" for input as #hvar$
    line input #hvar$, s$ 
    print s$
    close #hvar$

    end

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: handle variable with files
« Reply #1 on: May 17th, 2017, 6:58pm »

on May 17th, 2017, 5:32pm, wscbill wrote:
Getting the "handle used for incompatible devices" error in LBB when using a handle variable for files. Works successfully in LB.

If it works successfully in LB4 I think that's an anomaly, since my understanding is that handle variables can't be used in an OPEN statement. The correct method is surely to use MAPHANDLE as follows:

Code:
    fn = fn+1
    hvar$ = "#B" + str$(fn)
    print hvar$
    open "\temp\errors.txt" for input as #hvar
    maphandle #hvar, hvar$
    line input #hvar$, s$ 
    print s$
    close #hvar$ 

Richard.
« Last Edit: May 17th, 2017, 7:15pm by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: handle variable with files
« Reply #2 on: May 19th, 2017, 3:45pm »

on May 17th, 2017, 6:58pm, Richard Russell wrote:
If it works successfully in LB4 I think that's an anomaly, since my understanding is that handle variables can't be used in an OPEN statement.

Just to confirm that I've checked the LB4 documentation and nowhere is there any suggestion that a handle variable can be used in an OPEN statement: none of the examples show that and the description of the statement only mentions the use of a regular handle.

If the OP's report is correct and you can, at least in some circumstances, use a handle variable this is another example of LB working differently from what the documentation states. I would not consider the usage to be safe, and it does not work in LBB.

The correct, documented, method is to use MAPHANDLE as I showed in my example, which works in both LB 4 and LBB.

Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: handle variable with files
« Reply #3 on: May 25th, 2017, 4:42pm »

on May 19th, 2017, 3:45pm, Richard Russell wrote:
If the OP's report is correct and you can, at least in some circumstances, use a handle variable...

The report is not correct. The listed code which purports to demonstrate it working does nothing of the kind, as can be shown by running this example in LB 4.04:

Code:
    fn = fn+1
    hvar$ = "#B" + str$(fn)
    print hvar$
    open "\temp\errors.txt" for input as #hvar$
    print hvar$
    line input #B1, s$ 
    print s$
    close #hvar$ 

Printing hvar$ after the file has been opened shows that rather than the OPEN statement having opened the file with the handle #B1 as the OP claimed, it has in fact been opened with the handle #hvar1, so a subsequent attempt to read from the file with the expected handle given as a literal fails.

Richard.
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