
! script name: vdatatable.d/maketable
! var_topic: create an empty data table

!A
!A NAME:
!A
!A 	Create an empty data table VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Create an empty data table
!A
!B INSTRUCTIONS:
!B
!B 	NUMBER OF ROWS: Number of rows in table. A Row is horizontal.
!B
!B 	NUMBER OF COLUMNS: Number of columns: A Column is vertical.
!B
!B 	LOCATION: Input or pick the location of the upper left corner.
!B
!C NOTES:
!C
!C 	A datatable is an entity for the display and retention of tabular
!C 	data. A datatable consists of a square array of entries.  The data
!C 	in each entry may be sized, colored, justified, formatted, etc.
!C 	An entry in a table may be picked as an input.  Rows and columns
!C 	may be added at any time.
!C
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Create data table ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Point$[256]
DIM Rows_var$[256]
DIM Cols_var$[256]
DEG

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



ActivateUndo
Start:!
stat= SetInputFormat("n0","")
Num_rows= GetValue("NUMBER OF ROWS")
IF (ExitScript(Destination$)) THEN Leave
IF Num_rows < 1 THEN Num_rows=1
No_rows_var= LastVariableInput(Rows_var$)


stat= SetInputFormat("n0","")
Num_cols= GetValue("NUMBER OF COLUMNS")
IF (ExitScript(Destination$)) THEN Leave
IF Num_cols < 1 THEN Num_cols=1
No_cols_var= LastVariableInput(Cols_var$)

Center_point:stat= SetInputFormat("n4","")
E1=PickEntity("LOCATION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Center_point
Stat= EntityNameCheck(E1,Point$)
T1= LastPickPara
Pick_return1= CurrPickReturn
Pc= ParameterReturnPt(E1,T1,Pick_return1)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)



Stat= GenerateVarName(WsDataTableEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TABLE: create")
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,T1,WsGeomCenter)
END SELECT
IF No_rows_var THEN
	V1= FreeParameter("Number Rows",Num_rows)
ELSE
	V1= FreeParameter("Number Rows",Rows_var$)
END IF
IF No_cols_var THEN
	V2= FreeParameter("Number Cols",Num_cols)
ELSE
	V2= FreeParameter("Number Cols",Cols_var$)
END IF
V3= FreeParameter("Table origin",WsUpperLeft)
Table1= CreateBlankTable(Pc,"",V1,V2,V3,"        ")
Stat= NameEntity(Table1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

ActivateUndo
Stat= AdvanceUndoNumber("make table")
Stat= AddItemToUndo(WsUBCreateMode,Table1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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