
! script name: datatable.d/inputrow
! topic: Input a row into a datatable.

!A
!A NAME:
!A
!A 	Input Row
!A
!A DESCRIPTION:
!A
!A	Input a row into a datatable.
!A
!B INSTRUCTIONS:
!B
!B	ENTRY TYPE:  Text, Numeric, Symbol: Specify the entry type.
!B
!B	PICK START ENTRY: Pick the starting entry in the table.
!B
!B	INPUT NEW ENTRY:  Input the entry value.
!B
!C NOTE:
!C
!C	EXTENDED CHARACTER SET: Characters may be input by their ascii number.
!C 	Type in \031 for example to use the character in the font assigned to
!C	the ascii number 31. The code must be a three digit number from 001 to
!C 	255.  Some of the extended characters like the geometric tolerancing
!C 	symbols take up more than one space so they should be bracketed with
!C 	extra spaces.
!C
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: input row ")

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

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

Start:!
stat= SetInputFormat("a1=",",T,N,S,")
Stat= SetEqualsValue(0,"T")
stat= GetValue("ENTRY TYPE:  Text, Numeric, Symbol ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "T"
	Etype= WsStringEntry
	Format$="decimal 4"
CASE "N"
	Etype= WsNumericEntry
	Format$="noformat"
CASE "S"
	Etype= WsSymbolEntry
	Format$="decimal 4"
END SELECT

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

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


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

Num_columns= NumberTableCols(Element1)
SELECT Etype 
CASE WsStringEntry
	stat= SetInputFormat("a99","",WsFalse)
	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("input")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

	IF C1 > Num_columns THEN
		Stat= RedimTableColumns(Element1,C1)
	END IF

	Stat=InsertIntoTable(Element1,A$,R1,C1)
	Stat= PlotEntity(Element1)
CASE WsNumericEntry
	stat= SetInputFormat("n4=","")
	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("input")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

	IF C1 > Num_columns THEN
                Stat= RedimTableColumns(Element1,C1)
        END IF

        Stat=InsertIntoTable(Element1,Value,Format$,R1,C1)
	Stat= PlotEntity(Element1)
CASE WsSymbolEntry
        stat= SetInputFormat("a99","")
        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("input")
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

	IF C1 > Num_columns THEN
                Stat= RedimTableColumns(Element1,C1)
        END IF

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

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