shortening my sequencing records without writing each record
#11
To replace say record 16 in a sequential file, you have to set up a temporary file, write all the old data to it, except for the 16th record, which would be replaced with the new data. then kill the old file and name the temporary file as the old file.

Caution: running this code will overwrite any file you already have named myfile.dat and tmp.tmp.

Code: (Select All)
target = 16: replace$ = "My new data."
OPEN "MYFILE.dat" FOR INPUT AS #1
OPEN "tmp.tmp" for OUTPUT AS #2
DO UNTIL EOF(1)
i = i + 1
LINE INPUT #1, a$
IF i = target then a$ = replace$
PRINT #2, a$
LOOP
CLOSE #1, #2
KILL "MYFILE.dat
NAME "tmp.tmp" as "MYFILE.dat"

Of course to get this code to work, you'd have to make and fill the "MYFILE.dat" file.

Pete
Reply
#12
(09-27-2022, 09:00 PM)babyboomerboy Wrote: 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

Oh heck you just want to change file name. 

Code: (Select All)
Input "Enter record number or nothing to quit "; recordNumber$
If recordNumber$ <> "" Then
    Filename$ = "RECORD" + recordNumber$ + ".DAT"
    Open Filename$ 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
End If


For recall, depending what you want? This will both show the record and save it into an array for manipulation if desired.

Code: (Select All)
Input "Enter record number to Recall, or nothing to quit "; recordNumber$
If recordNumber$ <> "" Then
    Filename$ = "RECORD" + recordNumber$ + ".DAT"
    Dim aline(1 To 3, 1 To 8) As String
    Dim tyme(1 To 3, 1 To 8) As String
    Open Filename$ For Input As #1
    For TTP = 1 To 8
        For X = 1 To 3
            'show each line and load into an array
            Line Input #1, aline(X, TTP) ' use line input in case of commas  input into an array in case want to manipulate later
            Print aline(X, TTP)
            Line Input #1, tyme(X, TTP)
            Print tyme(X, TTP)
        Next X
    Next TTP
    Close #1
End If


PS I could not DIM Time as an array because it is a QB64 Keyword.
b = b + ...
Reply
#13
Quote:@Pete - To replace say record 16 in a sequential file, you have to set up a temporary file, write all the old data to it, except for the 16th record, which would be replaced with the new data. then kill the old file and name the temporary file as the old file.

That's alright. But the whole thing works in QB64. . . well, "krampfig" weird(?). There's better.
I have worked with MySQL + PostgreSQL before, and now I have looked at MySQL again. After initial retching, I now find my way around again a little and have created a first small database. For training.

So if you need a database like babyboomerboy, you might want to take a look at MySQL.
The installation is not difficult. Only I still have a problem setting it up. I would like to have my databases on the G:\ drive, but the corresponding settings are somehow not accepted. It stays in the default directory in C:\. Well, new task, new fun!  Tongue

[Image: DB-weinsorten-erstellt-2022-10-04.jpg]
Reply
#14
Deleting records in a sequential file, adding records, or changing records all use the same principle I demonstrated in my previous post to edit a record. You have to make a new file, edit, add, or delete a record as you create the new file then delete the old file and rename the new file to the old file name.

Pete
Reply
#15
(10-04-2022, 08:04 PM)Pete Wrote: Deleting records in a sequential file, adding records, or changing records all use the same principle I demonstrated in my previous post to edit a record. You have to make a new file, edit, add, or delete a record as you create the new file then delete the old file and rename the new file to the old file name.

Pete

Yes, in terms of a sequential database, but MySQL is a relational database management system (RDBMS). You don't need such crutches as in a sequential database, you can delete data records without moving the entire database back and forth. This is the crucial point! And more.

And you can correct records, very easily.
mysql> update <name> set XYZ = 'new name' where <name> = "XYZ";
Reply
#16
That's because the functions that operate that type of database are running sub-functions under the hood.

For editing records in QB64, RANDOM access files make it possible to overwrite a record, or make it a null record, without re-writing the file. Most of my office data was accessed with this file format; however, if I wanted to add new records inside of existing records, then I would write a sequential file; otherwise, you would need a function to GET and PUT each out of place record to a new record place. That reshuffling technique is a bit tricky, as I recall.

Pete
If eggs are brain food, Biden takes his scrambled.
Reply
#17
(10-04-2022, 09:10 PM)Pete Wrote: That's because the functions that operate that type of database are running sub-functions under the hood.

For editing records in QB64, RANDOM access files make it possible to overwrite a record, or make it a null record, without re-writing the file. Most of my office data was accessed with this file format; however, if I wanted to add new records inside of existing records, then I would write a sequential file; otherwise, you would need a function to GET and PUT each out of place record to a new record place. That reshuffling technique is a bit tricky, as I recall.

Pete

Sure, you can do it. I created programs in QuickBasic 4.X that save data sequentially and with direct access. I can't get to the larger one because there doesn't seem to be a program that can convert a QB 4.0x file.

But I printed out some of the source code, and now I've found a direct access file made with QB 4.0x. I have to get my head around how this works under Basic. But it's definitely more work than with MySQL.
Reply
#18
Certainly. Making advanced file routines for database management is a challenge in BASIC, but that's what BASIC is all about, taking the building blocks and making just about anything you want the way you want it... if you have the time.

Pete
Reply




Users browsing this thread: 9 Guest(s)