|
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
Posts: 104
|
Post by neal on Sept 5, 2008 22:13:12 GMT -5
You will need to make #subtest a global so it can be accessed from the subroutines.
|
|
neal
Full Member
Posts: 104
|
Post by neal on Sept 5, 2008 22:18:19 GMT -5
Actually that just gives me a different error :
Runtime Error in program 'untitled': put #subtest, x FIELD not found for handle: #subtest
It looks like there is a bug which doesn't allow the "field" command to work in a subroutine (I'm using beta 2 BTW).
|
|
|
Post by Psycho on Sept 5, 2008 23:02:48 GMT -5
Yep, I tried the global command as well but get the same error. I am also using beta 2 but I tried it in the released version with the same result
|
|
|
Post by carlgundel on Sept 6, 2008 0:25:03 GMT -5
Yep, I tried the global command as well but get the same error. I am also using beta 2 but I tried it in the released version with the same result Thanks for pointing this out, guys. I'll have a look. -Carl
|
|
|
Post by Psycho on Dec 13, 2008 23:31:22 GMT -5
Hi Carl,
Have you made any progress on this issue?
I've got another project started and it sure would make for cleaner code if I could open a random file with a subroutine rather than a gosub.
John "Psycho" Siejkowski
|
|
|
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
|
|
|
Post by Psycho on Jan 12, 2009 22:53:53 GMT -5
This is good news Carl I'm looking forward to a fix for that one. Thanks! John "Psycho" Siejkowski
|
|