I’m trying to delete a whole batch of fields that have invaded my database with a text import (I’ll try to track down the extra fields in the import separately).
When I do that programmatically, I get anomalous results. The data sheet continues to show the extra, unwanted fields, but show no name when I check them in the properties panel. W/hen I run a routine to show a list of field names, none of them show up in the list.
Here’s the procedure I ran:
local fn,flist
flist=info(“fields”)
fn=array(flist,arraysize(flist,cr()),cr())
field (fn)
loop
fn=info(“fieldname”)
field (fn)
if fn=“LastField” stop endif
deletefield
until info(“fieldname”)=“LastField”
Gary has uploaded a Reveal Invisible Text.pandb file to the exchange area. If you put your input data in that, you’ll more easily see how characters are influencing records and fields.
My guess is, you have errant commas (or tab) causing extra fields. Old school is to use the Replace function on the input to change all commas to some other unique character. Then, after import, if you want to keep them, you can change that character back to a comma.
“If the imported text contains more columns than the database, the importtext statement normally adds the extra fields needed to the database automatically.”
Zero idea. I created a database and literally copied your procedure text into the new database and ran it, it worked perfectly. I am running b26, but I don’t remember any change to the delete field code between b25 and b26.
FYI
array(flist,arraysize(flist,cr()),cr())
could be simplified to
arraylast(flist,cr())
For future reference, you can nip this issue in the bud by using the importtext statement with the ADDFIELDS option set to no.
Way better than what I was doing, having forgotten about the addfields option. I was attempting to import counting the fields until the last field of my database with info(“fields”) and arraysearch and then applying arrayfilter with arrayrange. Much messier.