
! script name: vdatatable.d/colvariables
! var_topic: make variables from a table column

!A
!A NAME:
!A
!A 	Tables: make variables from a table column	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will make a variable for each entry in a table column.
!A	The variables will be named using the base name as a prefix
!A	and the contents of column one as suffixes. Illegal name characters
!A	will be changed to "_" (underbars).
!A
!B INSTRUCTIONS:
!B
!B	VARIABLE BASE NAME: Enter the base variable name.
!B			A dependent variable will be made using the base
!B			name as its name. Then the contents of column 1
!B			will be used as suffixes to create a variable name
!B			for each column value.
!B
!B 	PICK TABLE COLUMN: Pick the table column to be used.
!B
!# see also - htdocs/help.d/datatables.htm

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

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 BASE 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
E1= FindNamedVar(Name$,WsVariationVars)
IF ValidGeometry(E1) THEN
        stat= SetInputFormat("a99","")
        Stat=GetValue("VARIABLE NAME IN USE, Proceed",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        GOTO Name_loop
END IF

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

RecordFunctionOn
Stat= RecordDescr("VARIABLE: Table column variables")
V1= FreeParameter("Column",C1)
V2=NumericVariable(Name$,WsVariationVars,VariableValue(V1))
G1= TableColVariables(Element$,EntityNameStr(V2),V1,WsVariationVars)
Stat= DeleteEntity(G1)
RecordFunctionOff
CloseVarRecord

GOTO Name_loop


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