
! script name: datatable.d/copycolumn
! topic: copy a column of table elements

!A
!A NAME:
!A
!A 	Copy column
!A
!A DESCRIPTION:
!A
!A 	Copy a column of table elements.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ORIGIN COLUMN: Pick the source column.
!B
!B 	PICK DESTINATION COLUMN: This is the copy's destination column.	
!B
!B NOTES:
!B
!B 	The origin table and the destination table may be the same.
!B 	In this case the copied data must not overlap.
!B
!B 	When tables are used in variational design the variational
!B 	attachments are not copied.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: copy column ")

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

ActivateUndo
Highlight_pen=2
Start:!

Element_loop:!
N1= DataTableCount
IF N1=0 THEN Leave
Pick_table:stat= SetInputFormat("n4","")
Table1=PickEntity("PICK ORIGIN COLUMN")
IF (ExitScript(Destination$)) THEN Leave
IF NOT  ValidGeometry(Table1) THEN Pick_table
T1= LastPickPara
R1=TableParaRow(Table1,T1)
C1=TableParaColumn(Table1,T1)


Pick_loop:!
Stat= PlotDataTable(Table1,1,C1,Highlight_pen)


Pick_dest:!
stat= SetInputFormat("n4","")
Table2=PickEntity("PICK DESTINATION COLUMN")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Table2) THEN Pick_dest
T1= LastPickPara
R3=TableParaRow(Table2,T1)
C3=TableParaColumn(Table2,T1)

Nr= NumberTableRows(Table1)
Nc= NumberTableCols(Table1)

ActivateUndo
Stat= AdvanceUndoNumber("copy column")
Stat= AddItemToUndo(WsUBModifyMode,Table2)

Stat= EraseEntity(Table2)
Stat= CopyTableRows(Table1,Table2,1,C1,Nr,C1,1,C3)
Stat= PlotEntity(Table2)
Stat= PlotDataTable(Table1,1,C1,Nr,C1,0)

GOTO Start

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