shortening my sequencing records without writing each record - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: shortening my sequencing records without writing each record (/showthread.php?tid=928) Pages:
1
2
|
shortening my sequencing records without writing each record - babyboomerboy - 09-27-2022 I have a program that writes a series of numbers to a file that I can recall. The problem is I have to go into the program each time I want to write a different record. OPEN "RECORD16.DAT" FOR OUTPUT AS #1 FOR TTP = 1 TO 8 FOR X = 1 TO 3 PRINT #1, ALINE(X, TTP) PRINT #1, TIME(X, TTP) NEXT X NEXT TTP CLOSE #1 I want to be able to make a new record :record16.dat without going to the program and changing it, record 17.dat, or record18.dat or whatever. I also want to be able to recall this new record. I hope I was able to explain this for someone to understand how I can add to my data base without doing it manually. Thank you RE: shortening my sequencing records without writing each record - SpriggsySpriggs - 09-27-2022 Would it not be worth it to just write all records to one file and then read them back? RE: shortening my sequencing records without writing each record - Dimster - 09-27-2022 Were you thinking of something like this R$="Record" Ext$=".DAT" For i = 16 to 18 Rnum$=str$(i) Open R$+LTRIM$(Rnum$)+Ext$ for Output as #i RE: shortening my sequencing records without writing each record - mnrvovrfc - 09-27-2022 Also decide if the first file, if the filenames are to be sorted, will be "RECORD1.DAT" or "RECORD01.DAT", for less than a hundred files. Because Windows file manager could boggle the mind with how it sorts by filename. If the OP only cares about "RECORD1.DAT" for the first file and "RECORD10.DAT" for the tenth, then the post by @Dimster is enough for the solution. Otherwise if the serial number must be two digits, must insert this line just below the "Rnum$" assignment: IF i < 10 Then Rnum$ = "0" + Ltrim$(Str$(i)) RE: shortening my sequencing records without writing each record - Pete - 09-27-2022 I'm not sure what you want. If I want to change records in an existing database, without rewriting the entire file, I can do that easily with a RANDOM access file, or with a SEQUENTIAL file, like the one you are referencing, with a few tricks. If you are talking about writing a new file name, then all you have to do is write a routine like Dimster described to make the next file, and do whatever you need to do to supply the data to fill that new file.' Pete RE: shortening my sequencing records without writing each record - babyboomerboy - 10-01-2022 (09-27-2022, 10:13 PM)Pete Wrote: I'm not sure what you want. I don't want to change the records that I have written in the sequential file but I don't want to have to go into the program and change the record number every time I want to add a file. The example I put up is repeated 16 times in my program because I don't know how to write a line that will change the record number and save the file. An example is; 310 ' -------------------------------------RECALL RECORD1.DAT GOSUB 900 ' THIS CLEARS ALL VARIABLES REC$ = (REC$ + "RECORD 1") OPEN "RECORD1.DAT" FOR INPUT AS #1 FOR TTP = 1 TO 8 FOR X = 1 TO 3 INPUT #1, ALINE(X, TTP) INPUT #1, TIME(X, TTP) NEXT X NEXT TTP CLOSE #1 RESULTS = 854736 GOTO 360 ' --------- GO TO DATA BREAK DOWN 320 ' ---------------------------------------RECALL RECORD2.DAT GOSUB 900 ' THIS CLEARS ALL VARIABLES REC$ = (REC$ + "RECORD 2") OPEN "RECORD2.DAT" FOR INPUT AS #1 FOR TTP = 1 TO 8 FOR X = 1 TO 3 INPUT #1, ALINE(X, TTP) INPUT #1, TIME(X, TTP) NEXT X NEXT TTP CLOSE #1 RESULTS = 431276 GOTO 360 ' -----------GO TO DATA BREAK DOWN 330 ' ----------------------------------------RECALL RECORD3.DAT GOSUB 900 ' THIS CLEARS ALL VARIABLES REC$ = (REC$ + "RECORD 3 ") OPEN "RECORD3.DAT" FOR INPUT AS #1 FOR TTP = 1 TO 8 FOR X = 1 TO 3 INPUT #1, ALINE(X, TTP) INPUT #1, TIME(X, TTP) NEXT X NEXT TTP CLOSE #1 RESULTS = 746352 I am looking for a line that will ask me what record number I want to use to save to data and then ask me what record I want to recall without having to write each record separately. I hope this explains it better. Thanks for your reply RE: shortening my sequencing records without writing each record - mnrvovrfc - 10-01-2022 This portion could be condensed easily like this: Code: (Select All) FOR iter = 1 TO 3 It shouldn't be too difficult to figure out how to involve the other files used in this project. RE: shortening my sequencing records without writing each record - RhoSigma - 10-01-2022 Here's our Wiki, go to the alphabetic keyword reference and lookup the commands INPUT and LINE INPUT, that's how you get ask for an input. RE: shortening my sequencing records without writing each record - Pete - 10-01-2022 @babyboomerboy Maybe this is what you are trying to do? Code: (Select All) LINE INPUT "What record do you want to access 1-16? "; rnum$ Safe to run, it won't create or alter any files. If this is what you need, you only have to remove demo lines and get rid of the '' (double rem marks) in the code. I recommend making a backup of your data files before adjusting your code. That way, if you are going to try writing to files, any mistakes won't destroy your saved work. Pete RE: shortening my sequencing records without writing each record - Kernelpanic - 10-01-2022 I haven't found anything about deleting records in a sequential file now. I once created a relational database in Cobol with insert, change, delete, and later a doubly linked list in C, and it could do that too. But it's been a long time. There doesn't seem to be anything like that in Basic? A simple example for a sequential file: Code: (Select All) 'Beispiel sequentielle Datei - 2. Okt. 2022 |