
! script name: vprocesstable.d/exchangerows
! var_topic: exchange two rows in the process table

!A
!A NAME:
!A
!A 	Modify Process Table: Exchange Rows	VARIATIONAL
!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 Table$[256]
DIM Data_name1$[256],Work_zone1$[256]
DIM Data_name2$[256],Work_zone2$[256]

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

First_pen=3
Second_pen=4
ActivateUndo
Start:!
Element_loop:!
Plot_table=0
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK FIRST ROW TO BE EXCHANGED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Table1) THEN Element_loop
IF NOT IsEntityDependent(Table1) THEN
	Stat= MessageFileBox("/usr/weber/database/messages/nonvdmprtbl","ERROR")
	GOTO Element_loop
END IF
Stat= EntityNameCheck(Table1,Table$)
IF Table$<>"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)
Plot_table=1

Stat= GetTableEntryStr("Amo process table",R1,1,Data_name1$)
Stat= GetTableEntryStr("Amo process table",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 IsEntityDependent(Table2) THEN Element_loop

IF NOT AreEntitiesSame(Table1,Table2) THEN Pick_second

T1= LastPickPara
R2=TableParaRow(Table1,T1)
IF R2=1 OR R2=R1 THEN Pick_second
Stat= PlotDataTable(Table1,R2,0,Second_pen)

Stat= GetTableEntryStr("Amo process table",R2,1,Data_name2$)
Stat= GetTableEntryStr("Amo process table",R2,2,Work_zone2$)

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

Stat= EraseEntity(Table1)
RecordFunctionOn
Stat= RecordDescr("TABLE: Exchange process table rows")
V1=StringConstant("Amo process table")
V2=StringConstant(Data_name1$)
V3=StringConstant(Work_zone1$)
V4=StringConstant(Data_name2$)
V5=StringConstant(Work_zone2$)
E1= FindNamedEntity(V1)
V6= FreeParameter("First row",ProcessTableRow(E1,V2,V3))
V7= FreeParameter("Second row",ProcessTableRow(E1,V4,V5))
Stat= ExchangeTableRows(E1,V6,V7)
RecordFunctionOn
Curr_record= CurrentVarRecord
CloseVarRecord
Stat= PlotEntity(Table1)
Plot_table=0

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Element_loop

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