
! script name: vdatatable.d/setlengthwidth
! var_topic: change table length and width.

!A
!A NAME:
!A
!A	Tables: Set Length, Width	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Set Table Length And Width.
!A
!B INSTRUCTIONS:
!B
!B	INPUT TABLE X LENGTH: Input Table Length along the X axis.
!B
!B	INPUT TABLE Y WIDTH: Input Table Width along the Y axis.
!B
!B NOTE:
!B
!B 	The table entries will expand or shrink proportionally to
!B 	match the table size. An input of zero allows dynamic sizing.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Set Table Length Width ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Element$[256]
DIM Table$[256]
DIM X_var$[256]
DIM Y_var$[256]
DEG

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

DEG


ActivateUndo
Start:!
Element_loop:!
N1= DataTableCount
IF N1=0 THEN Leave
IF N1 > 1 THEN
Pick_table:stat= SetInputFormat("n4","")
        Element1=PickEntity("PICK TABLE")
        IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidDependency(Element1) THEN Element_loop
	Stat= EntityNameCheck(Element1,Table$)
ELSE
        Element1= DataTableByNumber(1)
	IF NOT ValidDependency(Element1) THEN Element_loop
	Stat= EntityNameCheck(Element1,Table$)
END IF

Xlength:!
Xlen= TableLength(Element1)
stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Xlen)
Xlen= GetValue("INPUT TABLE X LENGTH ")
IF (ExitScript(Destination$)) THEN Leave
No_x_var= LastVariableInput(X_var$)

Ywidth:!
Ywid= TableWidth(Element1)
stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Ywid)
Ywid= GetValue("INPUT TABLE Y WIDTH ")
IF (ExitScript(Destination$)) THEN Leave
No_y_var= LastVariableInput(Y_var$)

S_mode=1
IF (Xlen>0) AND (Ywid = 0) THEN S_mode=2
IF (Xlen=0) AND (Ywid > 0) THEN S_mode=3


ActivateUndo
Stat= AdvanceUndoNumber("set length width")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Set Length, Width")
Stat=AutoSizeTable(Table$)
V3= FreeParameter("Size mode",S_mode)
IF No_x_var THEN
        V1= FreeParameter("Xlength",Xlen)
	IF No_y_var THEN
        	V2= FreeParameter("Ywidth",Ywid)
		Stat= SetTableLenWidth(Table$,V1,V2,V3)
	ELSE
		Stat= SetTableLenWidth(Table$,V1,Y_var$,V3)
	END IF
ELSE
	IF No_y_var THEN
        	V2= FreeParameter("Ywidth",Ywid)
		Stat= SetTableLenWidth(Table$,X_var$,V2,V3)
	ELSE
		Stat= SetTableLenWidth(Table$,X_var$,Y_var$,V3)
	END IF
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Element1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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