
! script name: vdatatable.d/varintotable
! var_topic: insert the value of a variable into a table

!A
!A NAME:
!A
!A 	Tables: Put Variable	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will insert the value of a variable into a table.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VARIABLE: Select the variable whose value will be inserted into
!B 		the table at the selected position.
!B
!B 	PICK ENTRY POSITION: Pick the entry position of the variable value.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: variable into table")

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DIM Format$[10]
DEG

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

A= GetDefault(WsPlacesAfter)
Format$= "decimal "&VAL$(A)

ActivateUndo
Start:!

Stat=UserSelectBox("VARIABLES","selected variable",WsVariationVars,WsVarSelect)
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT VARIABLE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Leave
N=POS(Answer$,"=")
IF N>1 THEN
        Answer$=Answer$[1,N-1]
        Answer$=TRIM$(Answer$)
END IF
Name$=Answer$
Var1=FindNamedVar(Name$,WsVariationVars)
IF NOT ValidGeometry(Var1) THEN Start


Pick_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK ENTRY POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Element1,Element$)
R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Var_type= NamedVarTyp(Name$)

ActivateUndo
Stat= AdvanceUndoNumber("entry: variable")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE ENTRY: Variable value")
V1= FreeParameter("Row",R1)
V2= FreeParameter("Column",C1)
RecordFunctionOff
IF Var_type= WsStringVar THEN
	RecordFunctionOn
	V3= FindNamedEntity(Name$)
	Stat= InsertIntoTable(Element$,V3,V1,V2)
	RecordFunctionOff
ELSE
	RecordFunctionOn
	Stat= InsertIntoTable(Element$,Name$,Format$,V1,V2)
	RecordFunctionOff
END IF
RecordFunctionOn
Stat= TableTextOrigin(Element$,V1,V2,WsRightCenter)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Element1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start


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