Author |
Topic: handle variable with files (Read 434 times) |
|
wscbill
New Member
member is offline
Posts: 2
|
|
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
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
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.
|
|
Logged
|
|
|
|
|