Random file not working with sub

new BookmarkLockedFalling
Psycho
Full Member
***

Psycho Avatar

Posts: 196

Post by Psycho on Sept 5, 2008 19:18:50 GMT -5

I have another problem that I'm not sure if it is a bug or not (but seems like it to me).
I have a program using a random access file for storing of data. I initially used a gosub routine to open the file but eventually programmed some subroutines that couldn't access it. I switched it to a sub for opening and a sub for closing and it would not work. I ended up leaving the gosub routine for opening it and writing a redundant sub that could be accessed by other subs. Another problem I had is some of the other subs won't properly access the random access file unless the gosub routine has been run sometime in the program first.

The following simple example should show the problem I'm having. This program works fine in Liberty Basic but gives the following error in RB:
Runtime Error in program 'untitled': put #subtest, x
Invalid handle: #subtest

[start]
filepath$="" 'for testing locally

call openfile
for x = 1 to 3
input "First Name ";name$
input "Last Name ";name2$
put #subtest, x
next x
call closefile

call openfile
for x = 1 to 3
gettrim #subtest, x
print name$;", ";name2$
next x
call closefile

[end]
print
print "Thanks, the program is complete."
end


sub openfile
' Open database
open filepath$+"subtest.dat" for random as #subtest len = 20
field #subtest, 10 as name,ドル 10 as name2$
end sub

sub closefile
close #subtest
end sub


Thanks for any help.

Psycho
neal
Full Member
***

neal Avatar

Posts: 104

neal
Full Member
***

neal Avatar

Posts: 104

Psycho
Full Member
***

Psycho Avatar

Posts: 196

carlgundel
Administrator
*****
Creator of Run BASIC

carlgundel Avatar

Posts: 975

Psycho
Full Member
***

Psycho Avatar

Posts: 196

Carl Gundel - admin
Administrator
*****

Carl Gundel - admin Avatar

Posts: 550

Post by Carl Gundel - admin on Jan 12, 2009 8:21:02 GMT -5

I'm working on this now. The issue is that when I moved from global handles by default that there is a little too much baggage. The FIELD statement specs are stored outside of the file references themselves and are referenced by handle name. This doesn't work when these things are local. So I will be moving the FIELD specs into the object that manages the file, so then it doesn't matter what scope you're in. So then if you can see the file you will also be able to get the FIELD spec.

-Carl
Psycho
Full Member
***

Psycho Avatar

Posts: 196