
! script name: vlogic.d/moverecord
! var_topic: move VDM record in object.

!A
!A NAME:
!A
!A 	Move VDM Record in Object
!A
!A DESCRIPTION:
!A
!A 	This script will allow a VDM record to be moved.
!A
!B INSTRUCTIONS:
!B
!B 	PICK RECORD TO BE MOVED,   Number: Pick the VDM record to be moved.
!B
!B 		N - Enter N to allow the VDM record number to be entered.
!B
!B 	PICK VARIATIONAL OBJECT: Pick the VDM object, or enter the
!B 		name of the VDM object containing the record to be deleted.
!B 		NOTE: This question is only asked if a record number has been
!B 		entered in response to the previous question.
!B
!B 	RECORD # IN OBJECT:  object_name: Enter the VDM record number of the
!B 		selected VDM object.
!B
!B 	PICK RECORD TO BE INSERTED BEFORE: Pick the record that the moved
!B 		record is to be inserted before. This record may be specified
!B 		by number.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: move variational record")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Object_name$[256]
DIM Descr$[256]
DIM A$[256]
DIM B$[256]
DIM Namelist$[32700]

DeActivateUndo
Stat=LineNumberIncr(1)
Global_color=3
Local_color=4
Highlight_color=2

Start:!
Pick_record:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK RECORD TO BE MOVED,   Number",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
	GOSUB Pick_object
	GOSUB Pick_by_number
	Moved_record=Var_record
	IF NOT ValidGeometry(Moved_record) THEN Pick_record
ELSE
	IF NOT ValidGeometry(E1) THEN Pick_record
	Moved_record=VarRecordParent(E1)
	IF NOT ValidGeometry(Moved_record) THEN Pick_record
	Var_object=VarObjectParent(E1)
	IF NOT ValidGeometry(Var_object) THEN Pick_record
END IF
Stat=Highlight(Moved_record,Highlight_color,0)
Stat=VarObjectName(Var_object,Object_name$)

Pick_insert:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK RECORD TO BE INSERTED BEFORE, Number",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
Record_number2:!
	GOSUB Pick_by_number
        Insert_record=Var_record
        IF NOT ValidGeometry(Insert_record) THEN Record_number2
ELSE
        IF NOT ValidGeometry(E1) THEN Pick_insert
        Insert_record=VarRecordParent(E1)
        IF NOT ValidGeometry(Insert_record) THEN Pick_insert
        Var_object2=VarObjectParent(E1)
        IF NOT ValidGeometry(Var_object2) THEN Pick_insert
	Stat=VarObjectName(Var_object2,Name$)
	IF Name$<> Object_name$ THEN Pick_insert
END IF
Stat=Highlight(Insert_record,Highlight_color,0)

Vrecnum= VarRecordNumber(Moved_record)
Irecnum= VarRecordNumber(Insert_record)

IF Vrecnum=Irecnum THEN Pick_record
IF Vrecnum=Irecnum-1 THEN Pick_record

Stat=MoveVarRecord(Moved_record,Insert_record)

Stat=VarObjectName(Var_object,Name$)
IF NOT LEN(Name$) THEN Pick_record
Close_object=0
Output_script=0
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputVarObject("tempscript",Name$,"vlogic.d/moverecord",Close_object,Output_script)
IF Stat=1 THEN Pick_record

LOAD "tempscript"

GOTO Pick_record

Pick_object:!
Nobjects= EntityTypeCount(WsVarObjectEnt)
IF Nobjects=1 THEN
	Var_object= CurrentVarObject
	IF NOT ValidGeometry(Var_object) THEN Leave
ELSE
	Var_object=PickVarObject("PICK VARIATIONAL OBJECT")
	IF ExitScript(Destination$) THEN Leave
	IF NOT ValidGeometry(Var_object) THEN Pick_object
END IF
Stat=VarObjectName(Var_object,Object_name$)
Stat=Highlight(Var_object,Highlight_color,0)
RETURN


Pick_by_number:!
Record_number1:!
Namelist$=""
Num_records= VObjectCount(Var_object)
FOR I=1 TO Num_records
        Var_record= VObjectRecord(Var_object,I)
        IF (ValidGeometry(Var_record)) THEN
          Stat= GetDescription(Var_record,Descr$)
          IF I= Rec_number1 THEN
                B$= ")     "
          ELSE
                B$= ")     "
          END IF
          OUTPUT A$ USING "4D,8A,#,K"; I,B$
	  IF ((LEN(Namelist$)+LEN(A$)+LEN(Descr$)) < 32600) THEN
          	Namelist$= Namelist$&A$&Descr$&","
	  END IF
        END IF
NEXT I

Stat=UserSelectBox("PICK RECORD","Record selected",0,WsForceSelect,Namelist$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT RECORD TO BE MOVED: ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$<>"" THEN
   SELECT UPC$(Answer$)
   CASE "CANCEL"
	GOTO Leave
   END SELECT
ON ERROR GOTO Record_number1
   Answer$=TRIM$(Answer$)
   IF NOT LEN(Answer$) THEN Record_number1
   Record_num= VAL(Answer$)
OFF ERROR
ELSE
   GOTO Record_number1
END IF
LowerSelectBox
Var_record=VObjectRecord(Var_object,Record_num)
IF NOT ValidGeometry(Var_record) THEN Record_number1
Stat=Highlight(Var_record,Highlight_color,0)
Stat=VarObjectName(Var_object,Object_name$)
RETURN

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

