
! script name: datatable.d/copyrow
! topic: copy a row of table elements

!A
!A NAME:
!A
!A 	Copy Row
!A
!A DESCRIPTION:
!A
!A 	Copy a row of table elements.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ORIGIN ROW: Pick the source row.
!B
!B 	PICK DESTINATION ROW: This is the copy's destination row.	
!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 row ")

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 ROW")
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,R1,1,Highlight_pen)


Pick_dest:!
stat= SetInputFormat("n4","")
Table2=PickEntity("PICK DESTINATION ROW")
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 row")
Stat= AddItemToUndo(WsUBModifyMode,Table2)

Stat= EraseEntity(Table2)
Stat= CopyTableRows(Table1,Table2,R1,1,R1,Nc,R3,1)
Stat= PlotEntity(Table2)
Stat= PlotDataTable(Table1,R1,1,R1,Nc,0)

GOTO Start

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