
! script name: datatable.d/changeentry
! topic: edit the entry in a datatable

!A
!A NAME:
!A
!A 	Edit Entry
!A
!A DESCRIPTION:
!A
!A 	This script allows an entry to be changed in a datatable entity.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTRY TO BE CHANGED: Pick the entry to be changed.
!B
!B 	INPUT NEW ENTRY: Input the new entry. The entry must be the same
!B 		type (e.g. String, Numeric, Symbol) as the existing entry.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: change data entry ")

DIM Answer$[4096]
DIM A$[4096]
DIM A1$[4096]
DIM Destination$[256]
DIM New_line$[10]
DIM End_line$[10]
DEG

ActivateUndo
New_line$= "\n"
End_line$= CHR$(10)

Start:!

Element_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK ENTRY TO BE CHANGED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Element1) THEN Element_loop
T1= LastPickPara

R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Stat= SetEntryHighlight(Element1,R1,C1,WsTrue)
Stat= PlotDataTable(Element1,R1,C1,0)

Etype= TableEntryType(Element1,R1,C1)


SELECT Etype 
CASE WsStringEntry
	Stat= GetTableEntryStr(Element1,R1,C1,Answer$)
	Stat= ReplaceString(Answer$,End_line$,"\n",A$)
	Stat= AddBackSlashChars(A$,Answer$)
	stat= SetInputFormat("a99=","",WsFalse)
	Stat=SetEditString(Answer$)
	stat= SetEqualsValue(0.0,Answer$)
	stat= GetValue("INPUT NEW ENTRY",Answer$)
	IF (ExitScript(Destination$)) THEN 
		Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
		GOTO Leave
	END IF
	Stat= BackSlashChars(Answer$,A1$)
	Stat= ReplaceString(A1$,New_line$,End_line$,A$)

	Stat= EraseEntity(Element1)
	Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
	ActivateUndo
	Stat= AdvanceUndoNumber("change entry")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

	Stat=InsertIntoTable(Element1,A$,R1,C1)
	Stat= PlotEntity(Element1)
CASE WsNumericEntry
	Value= GetTableValue(Element1,R1,C1)
	stat=  GetTableFormat(Element1,R1,C1,Format1$)

	stat= SetInputFormat("n4=","")
	Stat=SetEditValue(Value)
	stat= SetEqualsValue(Value)
        Value= GetValue("INPUT NEW ENTRY")
        IF (ExitScript(Destination$)) THEN
                Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
                GOTO Leave
        END IF

	Stat= EraseEntity(Element1)
	Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)

	ActivateUndo
	Stat= AdvanceUndoNumber("change entry")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

        Stat=InsertIntoTable(Element1,Value,Format1$,R1,C1)
	Stat= PlotEntity(Element1)
CASE WsSymbolEntry
	Stat= GetTableEntryStr(Element1,R1,C1,Answer$)
        stat= SetInputFormat("a99=","")
        stat= SetEqualsValue(0.0,Answer$)
        stat= GetValue("INPUT NEW SYMBOL CHARACTER",Answer$)
        IF (ExitScript(Destination$)) THEN
                Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
                GOTO Leave
        END IF

	Stat= EraseEntity(Element1)
	Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)

	ActivateUndo
	Stat= AdvanceUndoNumber("change entry")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)


        Stat=InsertIntoTable(Element1,Answer$,4,1,1,R1,C1)
        Stat= PlotEntity(Element1)
END SELECT

GOTO Element_loop

Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
