
! script name: processtable.d/exchangerows
! topic: exchange two rows in the process table

!A
!A NAME:
!A
!A 	Exchange Rows in Process Table	
!A
!A DESCRIPTION:
!A
!A 	This script exchanges the position of two rows in the process table.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ROW TO BE EXCHANGED: Pick the first row to be exchanged.
!B
!B 	PICK SECOND ROW TO BE EXCHANGED: Pick the row that to exchanged
!B		with the first row picked.
!B
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: exchange process table rows")

DIM Answer$[256],Destination$[256]
DIM A$[256]
DIM Data_name1$[256],Work_zone1$[256]
DIM Data_name2$[256],Work_zone2$[256]

IF NOT ValidGeometry("Amo process table") THEN Leave
First_pen=3
Second_pen=4
ActivateUndo
Element_loop:!
Plot_table=0
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK FIRST ROW TO BE EXCHANGED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Table1) THEN Element_loop
IF IsEntityDependent(Table1) THEN
	Stat= MessageFileBox("/usr/weber/database/messages/vdmprtbl","ERROR")
	GOTO Element_loop
END IF
IF NOT AreEntitiesSame(Table1,"Amo process table") THEN Element_loop

T1= LastPickPara
R1=TableParaRow(Table1,T1)
IF R1=1 THEN Element_loop
Stat= PlotDataTable(Table1,R1,0,First_pen)

Stat= GetTableEntryStr(Table1,R1,1,Data_name1$)
Stat= GetTableEntryStr(Table1,R1,2,Work_zone1$)

Pick_second:stat= SetInputFormat("n4","")
Table2=PickEntity("PICK SECOND ROW TO BE EXCHANGED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Table2) THEN Pick_second
IF NOT AreEntitiesSame(Table1,Table2) THEN Pick_second

T1= LastPickPara
R2=TableParaRow(Table1,T1)
Stat= PlotDataTable(Table1,R2,0,Second_pen)

Stat= GetTableEntryStr(Table1,R2,1,Data_name2$)
Stat= GetTableEntryStr(Table1,R2,2,Work_zone2$)

ActivateUndo
Stat= AdvanceUndoNumber("exchange rows")
Stat= AddItemToUndo(WsUBModifyMode,Table1)

Stat= EraseEntity(Table1)
Row1= ProcessTableRow(Table1,Data_name1$,Work_zone1$)
Row2= ProcessTableRow(Table1,Data_name2$,Work_zone2$)
Stat= ExchangeTableRows(Table1,Row1,Row2)
Stat= PlotEntity(Table1)

GOTO Element_loop

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