Deletefield not working properly

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”

Here’s the resulting datasheet:

‘LastField’ should be the end field. When I check flist after running the procedure, it shows ‘LastField’ as the last field.

Any ideas what’s happening here?

Running 10.2.0.b25 (3901) on 10.14.6

Interesting. I just force quit the database and reopened it, and the extraneous fields were gone. Weird.

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.

My guess is that this is only a cosmetic anomaly and might be more easily corrected by simply closing and reopening the Data Sheet…

The Help Page for the importtext statement says:

“If the imported text contains more columns than the database, the importtext statement normally adds the extra fields needed to the database automatically.”

Maybe that is what happened.

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.

If you’re using the openfile statement to do the import, you’ll need to switch the code to importtext instead.

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.

Thanks, Jim.