|
Post by PaulDZ on Jul 16, 2023 22:11:49 GMT -5
I am currently trying to reverse engineer a copy of ISAM routines designed for GWBASIC.
The problem I am having is trying to use variables for the name of the file, the length and the file number.
An example could be: OPEN Q$ FOR RANDOM AS #Q LEN=QL
During testing, the compile gets past the open statement only when the file name is a literal string such as "MyFile.dat"
When I try to use Q$="MyFile.dat" :Q=3:QL=192 and then OPEN Q$ FOR RANDOM as #Q LEN=QL the compile halts with a syntax error. Does anyone have a way to make this work?
Thanks in advance.
BTW, I have been given permission to share the ISAM routines. If anyone wants a copy, please ask.
|
|
|
Post by Rod on Jul 17, 2023 1:22:19 GMT -5
Did you include the FIELD statement immediately after the OPEN statement?
|
|
|
Post by tsh73 on Jul 17, 2023 3:12:45 GMT -5
My testing shows filename as a variable is ok But length as variables is no-no
Considereing random access files used via FEILD statement with constant length, variable length does not has sence?
How it was used in GWBASIC, did having length variable actually required/make sence?
|
|
|
Post by xxgeek on Jul 17, 2023 7:52:22 GMT -5
Edit - This post is not correct.
In Liberty Basic the line
OPEN Q$ FOR RANDOM as #Q LEN=QL
is actually 2 lines.
It should be written OPEN Q$ FOR RANDOM as #Q : LEN=QL
You get the syntax error because there is no : (colon) between the 2 lines.
What is QL the length of? If it represents the length of the file, then declare it. QL = len("MyFile.dat")
OPEN Q$ FOR RANDOM as #Q : QL = len("MyFile.dat") or Use 2 lines.
OPEN Q$ FOR RANDOM as #Q QL = len("MyFile.dat")'this gets the length of a file.
But as stated by others, you can't change the length of a file by stating it's length. A files length is determined by the amount of data within.
Edit - The above is totally wrong , sorry about that. I missed the class on the "open" command.
|
|
|
Post by tsh73 on Jul 17, 2023 7:57:11 GMT -5
Xxgeek, nope. Len is the part of open statement. It says how much bytes to get/put to random access file in one go.
|
|
|
Post by xxgeek on Jul 17, 2023 8:04:00 GMT -5
Xxgeek, nope. Len is the part of open statement. It says how much bytes to get/put to random access file in one go. hmmm, I better go look this up. Learn something new every time I see you Ok, my bad. Edit - Same in JB Sorry about that folks. Disregard my earlier post.
|
|
|
Post by PaulDZ on Jul 17, 2023 20:19:15 GMT -5
Did you include the FIELD statement immediately after the OPEN statement? Yes, the Field statements are there. I'll do more testing to see if it is the LEN statement that is being a problem.
|
|
|
Post by PaulDZ on Jul 17, 2023 21:12:00 GMT -5
My testing shows filename as a variable is ok But length as variables is no-no Considereing random access files used via FEILD statement with constant length, variable length does not has sence? How it was used in GWBASIC, did having length variable actually required/make sence? It all worked fine using GWBASIC. Yes, my testing shows the same thing. The LEN= statement works fine if you force a single value, but fails if using a variable. I can't reason out why this is. I can find no reasoning why the file name can be a variable, the file number can be a variable, but not the record length. I don't believe the creation of the record is made before actually opening the file. Another issue seems to be that I am unable to use an array item in the field statement. I'm sure I could work around this limitation, but the LEN= might be insurmountable. Interestingly, LB5 gives me different results. I'll keep working on it as time permits.
|
|
|
Post by tsh73 on Jul 18, 2023 0:04:13 GMT -5
|
|
|
Post by PaulDZ on Aug 6, 2023 22:13:40 GMT -5
|
|
|
Post by Walt Decker on Aug 7, 2023 10:37:44 GMT -5
You have to understand that a file is a bunch of byte size numbers. It mimics computer memory and computer memory contains only numbers. A RANDOM ACCESS file is a construct of the programming language. By convention, a RANDOM ACCESS file requires fixed length records in bytes so the "LEN =" tells the programming system how many bytes are in each record. Since the "LEN =" instruction tells the programming system how many bytes are in each record it makes no sense to state "LEN = 128" at one time and "LEN = 315" at another time for the same file. The change will produce corrupted data.
Most programming languages that have a random access system allow both text and numeric values in the same record. They use a deftype structure for this and the structure is defined prior to opening the file. The size of each record is based on the total byte size of the structure. LB is different. It regards all data as text, i. e. ansi character codes. That makes it very difficult to define a fixed length record that contains both text and numeric values.
|
|
|
Post by PaulDZ on Aug 8, 2023 0:38:06 GMT -5
it makes no sense to state "LEN = 128" at one time and "LEN = 315" at another time for the same file. The change will produce corrupted data. If you look at the files submitted, you would see that it is NOT trying to change the LEN of a file once opened. The LEN is dependent on the file it is opening at that time (designated by the variable "Q") For example: QF=1: ' ISAM Function OPEN Q=1: 'FILE NUMBER QL=5: 'length of file record QDATA=2: 'Associated data fileQ$="CUSTMAST.KEY": 'Name of fileGOSUB 60000: 'Access the ISAM routinesIt still makes no sense to me why the file name can be a variable, the file number can also be a variable. But not the length. The other problem I have come across is that the FIELD statement can not use an array variable. For example: Field #q,QL as Q$(Q,1) I'm sure this is just idiosyncrasies of the language.
|
|
|
Post by Chris Iverson on Aug 8, 2023 2:16:45 GMT -5
Are you able to give an example of how GWBASIC would handle this?
Because, as far as I'm aware for how RAF files work in LB, LEN can't be a variable because the very definition of the RAF file has to be set at compile time, and is unchangeable at runtime.
How would a variable size work, when the field definitions can't be changed, either?
If I have
size = 20 open "myfile" for random as #file LEN=size field #file, 10 as str1$, 10 as str2$
And then I change size to 30(or 15) without changing the field definitions, how would that even work? The size set by LEN has to equal the total of the sizes of each entry to the FIELD command.
I'm starting to suspect that the interface GWBASIC uses for RAF files is completely different to how LB handles them.
|
|
|
Post by tsh73 on Aug 8, 2023 6:39:09 GMT -5
my 0.02$ It's perfectly OK if you write a program with given file structure - you will hardly need to change these numbers (that's probably the only reason that noone objected before that variables did not allowed here in LB) But PaulDZ is working on a tool that should work with different files, and it becames an obstacle.
Why you could accept variable in LEN but not in FIELD? Just tested in QBasic (on virtual machine) - it does work with variables in LEN and FIELD
no problem, checked at FIELD statement
|
|
|
Post by Walt Decker on Aug 8, 2023 9:23:48 GMT -5
Personally, other than "text" files I never use LB's file system. If I want random access files I output/input all data as binary. That way I can build my own random access files that contain both ansi characters and numeric values. Since LB outputs numerics as ansi characters I change floats to their four or eight byte equivalants on output and change them back to numerics on input.
All the basic dialects with which I have worked and support random access use predefined structures for file IO. Then the "LEN" instruction becomes "LEN = SIZEOF(Structure)". It is more logical and much more flexible than LB's system.
I would like to take a look at those ISAM routines.
|
|