|
Post by DARKNIGHT on Jan 31, 2024 0:14:06 GMT -5
Hello All, I ran into another snag on my R/A File excursion. I might be grasping at straws here,
but, is there a way to set the Field statement Vals using a numeric variable? do the values HAVE to be constants? the reason I ask, is because I am writing a program to open different R/A files and they all won't have the same size fields as another.
on the field statement in my program, I am tried:
let A=30
OPEN "members.dat" FOR RANDOM AS #1 LEN=256 FIELD #1,_ ' set up the fields for file opened as #1 A AS Name$,_ ' 1st 30 bytes contains Name$, string 40 AS Address$,_ ' 2nd 110 bytes contains Address$, string 6 AS IDnumber ' 4th 6 bytes contains IDnumber, numeric
and LB gave me a nag box, that my total Field Len was incorrect. will I have to come up with forms that all have the same size field sizes as above, or have an individual field statement for each one? thanks in advance ..
PS: just realized that the total field size would also need to be changed using a numeric variable as well.... [Sighs] I get the feeling that I am beating a dead horse with this idea...
|
|
|
Post by tsh73 on Jan 31, 2024 3:44:28 GMT -5
Hello Jim I believe I've seen this question before. Someone tried to port some old DB library... Cannot find it
thanks, PaulDZ. Here's that thread: libertybasiccom.proboards.com/thread/2373/random-access-files-question
He got same problems: . cannot put field lengths as a variable I believe it just not supported in LB4 No specific reason, just was not here from the start. Some other BASICs allow this kind of stuff. It looks like LB5 allows this kind of thing But it is in alpha stage. Somehow putting example from a Help file ended up with error message written into that file ( No idea where error was EDIT found it. Probably a bug - then you skip record 1, it pust some garbage in it. This code based on example "contact_lb5.bas" in LB5 bas_files folder. Program itself does not work for me (error with missing GOSUB), but this part of code - works You see, I used variable (x1) and array member (y(2)) as length, and variable (total) as record size Accoring to resulting file length, it used "total". dim y(10) y(2)=15 x1=20 total = 700 'it looks like LB5 uses this number and does not checks filed length sum
open "contact3.dat" for random as #contacts len = total field #contacts, _ x1 as name$, _ y(2) as address$, _ 15 as city$, 2 as state$, 10 as zip$, 15 as phone$, 20 as stage$, 500 as memo$, 48 as fill$
address$="Nowhere, 123" name$ = "4" put #contacts, 1 name$ = "Carlos Gomez" stage$ = "Initial Phone Call" put #contacts, 2 name$ = "Raymond Rhodes" stage$ = "Special Offer Mailer" put #contacts, 3 name$ = "Willie Weston" stage$ = "Initial Phone Call" put #contacts, 4 name$ = "Alexi Guerra" stage$ = "Special Offer Mailer" put #contacts, 5 close #contacts
print "over" run "notepad.exe "+DefaultDir$+"\contact3.dat"
|
|
|
Post by PaulDZ on Jan 31, 2024 4:15:12 GMT -5
I ran into these issues when trying to port some old ISAM routines over to LB. Some of the issues I encountered could be circumvented, others couldn't. I tried to use a variable to set the file record size using a variable. Not possible using LB4. I also tried to use array entries as the field statements and this didn't work either. I could get around that by tracking the information in the arrays and copying the values to a standard variable before writing the records.
I may try writing another ISAM routine using LB but I believe it has already been done. If I get some free time I'll look into the ISAM routines out there. .One of the best parts of the routines I uploaded is that it would take into account for deleted records and reuse the space. It was also easy to sort the key files using a well built bubble sort. All by setting a few variables (like file number, size, etc).
Good luck with what you are trying to do.
|
|
|
Post by badbug on Jan 31, 2024 4:52:46 GMT -5
Why not simply put it in SQLite. Then you can enter whatever you want. And SQLite is faster and easer to use thatn R/A.
' -------------------------------------- ' create in memory database table ' -------------------------------------- sqliteconnect #sql, ":memory:" sql$ = "CREATE TABLE people ( perNum int(4), name varchar(22), addr varchar(22), city varchar(12), state char(2), zip char(10) )" #sql execute(sql$) ' load with some data sql$ = "INSERT INTO people VALUES (1,'John','123 main','Los Angelos','CA','98765')" print sql$ #sql execute(sql$)
for i = 2 to 100 perNum = i name$ = "name";int(100 * rnd(1)) addr$ = "addr";i city$ = "city";i state$ = "state";i zip$ = "zip";i
sql$ = "INSERT INTO people VALUES (";perNum;",'";name$;"','";addr$;"','";city$;"','";state$;"','";zip$;"')" print sql$ #sql execute(sql$)
next i print "=============================================" print " -------- print loaded file in name seq -----" sql$ = "SELECT * FROM people ORDER BY name" #sql execute(sql$) rows = #sql ROWCOUNT() 'Get the number of rows print "# rows in table ";rows WHILE #sql hasanswer() result$ = #sql nextrow$(chr$(9)) print result$ WEND end
|
|
|
Post by PaulDZ on Jan 31, 2024 6:04:27 GMT -5
Why not simply put it in SQLite. Then you can enter whatever you want. And SQLite is faster and easer to use thatn R/A. The idea is to have control over the files using only BASIC. The routines I'm trying to port to LB came long before SQL. It is more of a labor of love, rather for any purely practical reason.
|
|
|
Post by DARKNIGHT on Jan 31, 2024 16:03:32 GMT -5
OK thanks guys, I don't have that many forms, so I'll just have to create an individual Field statement for each one.
as I am not familier with SQL, and not advanced enough in LB to do any trouble shooting to find out why your code didn't work.
|
|