
! script name: vdatatable.d/addcolumns
! var_topic: add columns to a table

!A
!A NAME:
!A
!A 	Add Columns
!A
!A DESCRIPTION:
!A
!A 	Add  blank columns to the end of a table
!A
!B INSTRUCTIONS:
!B
!B 	PICK TABLE: Select the table to be modified.
!B
!B 	NUMBER OF COLUMNS ADDED: Number of columns added to the end.
!B
!B NOTES:
!B
!B 	The data in the table is preserved when adding columns or rows.
!B
!B 	To insert blank columns in the interior of a table
!B 	use insert column.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: add columns ")

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

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


ActivateUndo
Start:!

Element_loop:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK TABLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table1) THEN Element_loop
Stat= EntityNameCheck(Table1,Table$)


stat= SetInputFormat("n0=","")
Stat=SetEqualsValue(Ncols)
Ncols= GetValue("NUMBER OF COLUMNS ADDED",Answer$)
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("add columns")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Add columns")
V1= FreeParameter("Number columns",Ncols)
V2= FreeParameter("Addon",1)
Stat= RedimTableColumns(Table$,V1,V2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)

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
