Adding many new records to a DB

Hi, after a long absence I am delving into Panorama X again converting my hand-written records of many years ago.
The following problems have come up, which I did not yet find a solution for:

  1. Once the DB structure is in place I’d like to add many new (empty) records which then will be gradually filled in by hand. Instead of clicking 1750 times on “Add” (a new record), I’d expect to click somewhere to add a new record and enter a number of how many of them. Is there such an option?
  2. When entering the new empty records, I’d like to add a running number to each of them. This will be the only distinctive characteristic of a record. It should be a serial number beginning with 1 and increasing in steps of 1 for each consecutive record (1,2,3,…,1750). Something like this used to exist in Panorama 6, as I remember vaguely, but I didn’t discover it in Panorama X.
    Can anybody help? Thanks a lot
    Andy

Each of the databases in my project has a unique key field consisting of a unique integer prefixed by a letter identifying the database, and this .newrecord procedure:

if info("trigger") = "New.Add" addrecord
    elseif info("trigger") = "New.Insert" insertrecord
    elseif info("trigger") = "New.Return" insertbelow
endif
KEY=uniqueid("KEY","N")

where "N" is the prefix for that particular database. The integers are not guaranteed to run from 1 to the number of records, because if a record is deleted its number isn’t reused when another is created, but it fulfils the purpose of a unique key field.

. . . and KEY is the field in each database containing the primark key, I should have said.

There are a number of ways to accomplish it. For simply getting your records entered a procedure such as this will work:

Let lvNum = “1”
GetText “Add How Many?”,lvNum
lvNum = val(lvNum)
Loop
AddRecord
lvNum = lvNum-1
Until lvNum = 0

You can add a counting variable to figure the serial number and insert it into a field on each addition, or set a numeric field with a default value of +1.

Faster than a loop: Create an array of the wanted size and append it to your database.
For the ID number you can fill the numeric ID field with our wanted sequence.
When you occasionally add single records, too, you might want to set an automatic increment in the field’s properties.

Here is a code sample:

local n, x
n = 1750
x = rep(¶,n-1)
ArrayFilter x,x,¶,pattern(seq(),"####")
openfile "&@x"

Just to make things simple, you can use the addlines statement to add an entire block of new records to your serial number field. Say your serial number field is named SerialNumber and is set to Integer. From your description I assume you want to start the new records from 1 and end up with 1750 new records with the SerialNumber field numbered consecutively from 1 to 1750. Make a procedure and simply use this code:

addlines SerialNumber, 1, 1750, 1

You will now have 1751 records because you started with a blank record. You can now go and delete the original blank starting record or if you had already numbered that record to number 1 you can alter the code to keep that record and add 1749 new records starting with number 2:

addlines SerialNumber, 2, 1749, 1

Hi, Gary,
thanks a lot, your simple solution solved my problem. Great help!
Thanks to all others as well, who replied!
Andy

For anyone that might come across this thread later, I want to mention that Panorama X has a much better way to import text from a variable. Instead of using openfile with a hard to remember prefix, use the importtext statement. Here is code that will perform the same action as openfile "&@x"

importtext x,"existingdata","replace"

If you want to append instead of replace, it’s even simpler.

importtext x

My recommendation would be to avoid the use of the legacy openfile statement in new code. It’s kind of a jack-of-all trades that makes it hard to remember how to use correctly. If you want to open a database, use the opendatabase statement, if you want to import text, use importtext or opentextfile, if you want to append one database into another use importdatabase.

By the way, if you look at the source code for the addlines statement Gary suggested, you’ll see that it is actually implemented using the arrayfilterand importtext statements. So essentially Kurt and Gary’s suggestions are the same, just addlines allready had the code written for you.