
! script name: vdatatable.d/sizecolumn
! var_topic: auto size a column in a table

!A
!A NAME:
!A
!A 	Column Size	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script auto sizes a column of entries in a table.
!A
!B INSTRUCTIONS:
!B
!B	PICK COLUMN TO BE SIZED: Pick the column to be autosized.
!B
!B	MINIMUM NUMBER OF CHARACTERS: Enter the minimum number of character
!B 		spaces in a column.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: auto size column ")

DIM Answer$[256]
DIM A$[256]
DIM Destination$[256]
DIM Table$[256]

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

Num_lines=1
Num_chars=0

ActivateUndo
Start:!
N1= DataTableCount
IF N1=0 THEN Leave

Element_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK COLUMN TO BE SIZED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Element_loop
Stat= EntityNameCheck(Element1,Table$)
T1= LastPickPara

R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Stat= SetEntryHighlight(Element1,R1,C1,WsTrue)
Stat= PlotDataTable(Element1,R1,C1,0)

stat= SetInputFormat("n0=","")
Stat=SetEqualsValue(Num_chars)
Num_chars= GetValue("MINIMUM NUMBER OF CHARACTERS",Answer$)
IF (ExitScript(Destination$)) THEN
        Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
        GOTO Leave
END IF


ActivateUndo
Stat= AdvanceUndoNumber("size column")
Stat= AddItemToUndo(WsUBModifyMode,Element1)

Stat= EraseEntity(Element1)
Stat= SetEntryHighlight(Element1,R1,C1,WsFalse)
RecordFunctionOn
Stat= RecordDescr("TABLE: size column")
V1= FreeParameter("Minimum number of characters",Num_chars)
V2= FreeParameter("Column",C1)
Stat=AutoSizeTable(Table$,V1,0,0,V2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Element1)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Element_loop

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