
! script name: vdatatable.d/vtableentry
! var_topic: make variable from table entry

!A
!A NAME:
!A
!A 	Tables: Assign Variable		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will make a variable from a row column entry in a datatable.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME: Enter the variable name.
!B
!B 	INVALID VARIABLE NAME, Proceed: The variable name input was invalid,
!B 		enter "P" to enter a different variable name.
!B
!B 	PICK ENTRY: Pick the entry to be used.
!B
!# see also - htdocs/help.d/datatables.htm

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

DIM Answer$[256]
DIM A$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DEG

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

DeActivateUndo
Name_loop:!
stat= SetInputFormat("a99","")
Stat=GetValue("VARIABLE NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Name$= Answer$
IF NOT ValidVariableName(Name$)	THEN
	stat= SetInputFormat("a99","")
	Stat=GetValue("INVALID VARIABLE NAME, Proceed",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	GOTO Name_loop
END IF

Pick_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK ENTRY ")
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)

Etype= TableEntryType(Element1,R1,C1)
SELECT Etype
CASE WsStringEntry
	Stat= GetTableEntryStr(Element1,R1,C1,A$)
	IF IsStringNumeric(A$) THEN 
		Numeric_entry=1
	ELSE
		Numeric_entry=0
	END IF
CASE WsNumericEntry
		Numeric_entry=1
CASE ELSE
	stat= SetInputFormat("a99","")
	Stat=GetValue("INVALID ENTRY TYPE , Proceed",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	GOTO Name_loop
END SELECT

RecordFunctionOn
Stat= RecordDescr("VARIABLE: Table Entry")
V1= FreeParameter("Row",R1)
V2= FreeParameter("Column",C1)
IF Numeric_entry THEN
	V3=NumericVariable(Name$,WsVariationVars,GetTableValue(Element$,V1,V2))
	stat= SetVariableDescr(V3,"Table Entry:")
ELSE
	V3=CreateVariable(Name$,WsVariationVars,"  ")
	Stat= GetTableEntryStr(Element$,V1,V2,V3)
END IF
RecordFunctionOff
CloseVarRecord

GOTO Name_loop


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