delete TAB LF CR from all text fields in database

jevgjemjevgjem Member Posts: 17
Good day.
Somehow happens, that users by copy-pasting from Excel had enough "wrong" symbols in NAV database in all places. I have searched fast solution in forums, didn’t find it. Write code by myself, if someone will need this again:

Variables
Name DataType Subtype Length
Object Record Object
RecRef RecordRef
FldRef FieldRef
Ch Text 3
i Integer
TmpText Text 1024
Window Dialog
RecNo Integer (2 dimensions)
TotalRecNo Integer (2 dimensions)

Code


Ch[1] := 9; // TAB
Ch[2] := 10; // LF
Ch[3] := 13; // CR

Object.RESET;
Object.SETRANGE(Type,Object.Type::TableData);
IF Object.FINDSET THEN BEGIN
Window.OPEN('Update Text fields @ \'+
'company #2###################### \ '+
'table #3###################### \ '+
'records @');
RecNo[1]:=0;
TotalRecNo[1]:=Object.COUNT;

REPEAT
RecNo[1] += 1;
Window.UPDATE(1,ROUND(RecNo[1] / TotalRecNo[1] * 10000,1,'<'));
Window.UPDATE(2,Object."Company Name");
Window.UPDATE(3,Object.Name);

RecRef.OPEN(Object.ID,FALSE,Object."Company Name");
IF RecRef.FINDSET THEN BEGIN
RecNo[2]:=0;
TotalRecNo[2]:=RecRef.COUNT;

REPEAT
RecNo[2] += 1;
Window.UPDATE(4,ROUND(RecNo[2] / TotalRecNo[2] * 10000,1,'<'));

FOR i := 1 TO RecRef.FIELDCOUNT DO BEGIN
CLEAR(FldRef);
FldRef := RecRef.FIELDINDEX(i);
IF FORMAT(FldRef.TYPE) IN THEN BEGIN
TmpText := FldRef.VALUE;
TmpText := DELCHR(TmpText, '=', Ch);
FldRef.VALUE(TmpText)
END;
END;
RecRef.MODIFY;
UNTIL RecRef.NEXT=0;
END;
RecRef.CLOSE;
UNTIL Object.NEXT=0;
END;
Sign In or Register to comment.