// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // ! This script is provided "as is" by Applied Maths. ! // ! You are free to use and modify this script for your own needs. ! // ! Redistribution or reproduction of the script is prohibited. ! // ! DISCLAIMER: ! // ! Improper use of scripts may corrupt your database. ! // ! Running this script is entirely at your own responsibility. ! // ! Applied Maths accepts no lialibility for any consequences ! // ! resulting from its use. ! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! integer i,j,inuse[],ok; string key,fieldlist,fieldsellist,st,st2; DIALOG dlg; if DbGetFieldCount=0 then { message("There are no database fields in this database"); stop; } for i=1 to DbGetEntryCount do { key=DbGetEntryKey(i); for j=1 to DbGetFieldCount do if DbGetField(key,DbGetFieldName(j))<>"" then inuse[j]=1; } //check if some fields are not used ok=0; for j=1 to DbGetFieldCount do if not(inuse[j]) then ok=1; if not(ok) then { message("All fields are used in at least one entry"); stop; } //prompt which fields may be removed for j=1 to DbGetFieldCount do if not(inuse[j]) then fieldlist=fieldlist+DbGetFieldName(j)+" "; fieldsellist=fieldlist; DlgAddText(dlg,"The following fields are not used. Select the fields you want to remove",15,15,200,30); DlgAddList(dlg,fieldlist,fieldsellist,15,50,170,220,"MULTI"); if not(DlgShow(dlg,"Remove unused fields",300,290)) then stop; if fieldsellist="" then stop; //ask for confirmation DlgReset(dlg); st2=fieldsellist; while st2<>"" do { st=st+"~""+splitstring(st2," ")+"~""; if st2<>"" then st=st+" , "; } DlgAddText(dlg,"Are you sure you want to delete the following fields:",15,15,280,15); DlgAddText(dlg,st,15,37,280,45); DlgAddButton(dlg,"No",12,160,100,100,25); DlgAddButton(dlg,"Yes",11,40,100,100,25); DlgAddText(dlg," WARNING: pressing 'Yes' may permanently remove data from your database!",15,150,280,30); if DlgShow(dlg,"Confirmation",310,220)<>11 then stop; while fieldsellist<>"" do DbDelField(splitstring(fieldsellist," "));