
! script name: vdatatable.d/inputcolumn
! var_topic: Input a column into a datatable

!A
!A NAME:
!A
!A 	Tables: Input Column		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows input into a datatable.
!A
!B INSTRUCTIONS:
!B
!B 	ENTRY TYPE:  Text, Numeric, Symbol: Select the type of input.
!B
!B 		T - Enter "T" for text input.
!B 		N - Enter "N" for numeric input.
!B 		S - Enter "S" to enter a symbol.
!B
!B 	PICK START ENTRY: Pick the position in the table for the first
!B
!B 	PICK START ENTRY: Pick the position in the table for the first
!B 		entry.
!B
!B 	INPUT NEW ENTRY: Enter the entry.
!B
!B 	INPUT NEW SYMBOL CHARACTER: Enter the symbol.
!B
!C NOTE:
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their ascii
!C 	number.  Type in \031 for example to use the character in the
!C 	font assigned to the ascii number 31. The code must be a three
!C 	digit number from 001 to 255.  Some of the extended characters
!C 	like the geometric tolerancing symbols take up more than one
!C 	space so they should be bracketed with extra spaces.
!C
!# see also - htdocs/help.d/datatables.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: table input column ")

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

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

ActivateUndo
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

Stat= EntityNameCheck(Element1,Table$)
R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)
Rstart= R1
Cstart= C1


Next_entry:!
Num_columns= NumberTableCols(Element1)
Num_rows= NumberTableRows(Element1)
IF R1> Num_rows THEN 
		C1= C1+1
		R1= Rstart
END IF

IF C1 > Num_columns THEN Leave
Stat= PlotDataTable(Element1,R1,C1,-1)
Stat= SetEntryHighlight(Element1,R1,C1,WsTrue)
Stat= PlotDataTable(Element1,R1,C1,0)
SELECT Etype 
CASE WsStringEntry
	stat= SetInputFormat("a99","",WsFalse)
	stat= GetValue("INPUT NEW ENTRY",Answer$)
	IF (ExitScript(Destination$)) THEN 
		Stat= PlotDataTable(Element1,R1,C1,-1)
                Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
                Stat= PlotDataTable(Element1,R1,C1,0)
		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)

	B$= "TABLE ENTRY:  "&A$

	ActivateUndo
	Stat= AdvanceUndoNumber("entry:"&A$)
	Stat= AddItemToUndo(WsUBModifyMode,Element1)

	RecordFunctionOn
	Stat= RecordDescr(B$)
	V1= FreeParameter("Row",R1)
	V2= FreeParameter("Column",C1)
	V3= StringConstant(A$)
	Stat=InsertIntoTable(Table$,V3,V1,V2)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord
	Stat= PlotEntity(Element1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

CASE WsNumericEntry
	stat= SetInputFormat("n4=","")
	stat= SetEqualsValue(Value)
        Value= GetValue("INPUT NEW ENTRY")
        IF (ExitScript(Destination$)) THEN
		Stat= PlotDataTable(Element1,R1,C1,-1)
                Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
                Stat= PlotDataTable(Element1,R1,C1,0)
                GOTO Leave
        END IF
        Stat= EraseEntity(Element1)
        Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)

	B$= "TABLE ENTRY:  "&VAL$(Value)

	ActivateUndo
        Stat= AdvanceUndoNumber("entry:"&VAL$(Value))
        Stat= AddItemToUndo(WsUBModifyMode,Element1)

	RecordFunctionOn
	Stat= RecordDescr(B$)
	V3= FreeParameter("Value",Value)
	V1= FreeParameter("Row",R1)
	V2= FreeParameter("Column",C1)
	V4= StringConstant(Format$)
	Stat=InsertIntoTable(Table$,V3,V4,V1,V2)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord
	Stat= PlotEntity(Element1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

CASE WsSymbolEntry
        stat= SetInputFormat("a99","")
        stat= GetValue("INPUT NEW SYMBOL CHARACTER",Answer$)
        IF (ExitScript(Destination$)) THEN
		Stat= PlotDataTable(Element1,R1,C1,-1)
                Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
                Stat= PlotDataTable(Element1,R1,C1,0)
                GOTO Leave
        END IF
        Stat= EraseEntity(Element1)
        Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)

	ActivateUndo
        Stat= AdvanceUndoNumber("entry symbol:"&Answer$)
        Stat= AddItemToUndo(WsUBModifyMode,Element1)

	RecordFunctionOn
	Stat= RecordDescr("TABLE ENTRY: symbol")
	V1= FreeParameter("Row",R1)
	V2= FreeParameter("Column",C1)
	V3= StringConstant(Answer$)
	Stat=InsertIntoTable(Table$,V3,4,1,1,V1,V2)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord
	Stat= PlotEntity(Element1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

END SELECT
	R1= R1+1
	C1= C1
GOTO Next_entry

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