
! script name: vcontrol.d/reccalcsonoff
! var_topic: turns the calculations in a single record on or off.

!A
!A NAME:
!A
!A 	Record Calculations On/Off
!A
!A DESCRIPTION:
!A
!A 	This script will turn on/off calculations in a single record.
!A
!B INSTRUCTIONS:
!B
!B 	PICK VARIATIONAL RECORD, New Object , On , Off ",Answer$)
!B
!B 		New Object - Choose a new object to modify
!B		On - Turn all records on
!B		Off - Turn all records off
!B		S,Switch - Flips ON/OFF on all records
!B
!B 	PICK VARIATIONAL OBJECT: Pick the VDM object, or enter the
!B 		name of the VDM object containing the record.
!B 		NOTE: This question is only asked if a record number has been
!B 		entered in response to the previous question.
!B
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: record calculations on/off")

DIM Destination$[256]
DIM Answer$[512]
DIM Name$[256]
DIM Object_name$[256]
DIM Descr$[256],On_off$[256]
DIM Namelist$[32000],A$[128]

DeActivateUndo
Curr_obj= CurrentVarObject
Highlight_color=4

Start:!
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$)
Vstat=OpenVarObject(Object_name$)

Pick_record:!
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$)
	  On_off= IsRecordCalcsOn(Var_record)
	  IF On_off=WsTrue THEN
		On_off$= ")  ON  "
	  ELSE
		On_off$= ") OFF  "
	  END IF
	  OUTPUT A$ USING "4D,8A,#,K"; I,On_off$
	  Namelist$= Namelist$&A$&Descr$&","
	END IF
NEXT I

Stat=GeneralListBox(D_label$,"RECORD CHOSEN",Namelist$)
Stat=SetInputFormat("a99","")
IF Nobjects> 1 THEN
E1=PickEntity("PICK VARIATIONAL RECORD, New Object , On , Off , Range ",Answer$)
ELSE
E1=PickEntity("PICK VARIATIONAL RECORD, On , Off , Range ",Answer$)
END IF
IF ExitScript(Destination$) THEN Leave
IF Answer$<>"" THEN
	SELECT UPC$(Answer$)
	CASE "CANCEL"
		LowerSelectBox
		IF Nobjects>1 THEN
			GOTO Pick_object
		ELSE
			GOTO Leave
		END IF
	CASE "NEW","OBJECT"
		GOTO Pick_object
	CASE "RANGE","R"
Start_record: 	OFF ERROR
		Stat=GeneralListBox(D_label$,"RECORD CHOSEN",Namelist$)
		Stat= SetInputFormat("a99","")
		E1=PickEntity("PICK STARTING RECORD ",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$<>"" THEN
			IF Answer$= "CANCEL" THEN Start_record
			ON ERROR GOTO Start_record
			Answer$=TRIM$(Answer$)
			Var_record1= VObjectRecord(Var_object,VAL(Answer$))
			OFF ERROR
		ELSE
			IF NOT ValidGeometry(E1) THEN Start_record
			Var_record1=VarRecordParent(E1)
			IF NOT ValidGeometry(Var_record1) THEN Start_record
			Stat=Highlight(Var_record1,Highlight_color,0)
		END IF
		Num1= VarRecordNumber(Var_record1)
		LowerSelectBox
Second_record:  OFF ERROR
		IF Num1>1 THEN
			OUTPUT A$ USING "4D,#,K"; Num1
			K= POS(Namelist$,","&A$&")")
			IF K>1 THEN Namelist$= Namelist$[K+1]
		END IF
		Stat=GeneralListBox(D_label$,"RECORD CHOSEN",Namelist$)
		E2=PickEntity("PICK ENDING RECORD ",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$<>"" THEN
			IF Answer$= "CANCEL" THEN Second_record
			ON ERROR GOTO Second_record
			Answer$=TRIM$(Answer$)
			Var_record2= VObjectRecord(Var_object,VAL(Answer$))
			OFF ERROR
		ELSE
			IF NOT ValidGeometry(E2) THEN Second_record
			Var_record2=VarRecordParent(E2)
			IF NOT ValidGeometry(Var_record2) THEN Second_record
		END IF
		Num2= VarRecordNumber(Var_record2)
		IF Num1>=Num2 THEN Second_record
		True_count= 0
		False_count= 0
		FOR I= Num1 TO Num2
			Var_record= VObjectRecord(Var_object,I)
			On_off= IsRecordCalcsOn(Var_record)
			IF On_off=WsTrue THEN
				True_count= True_count+1
			ELSE
				False_count= False_count+1
			END IF
		NEXT I
		On_off_sw= WsFalse
		IF True_count<False_count THEN On_off_sw= WsTrue
		FOR I= Num1 TO Num2
			Var_record= VObjectRecord(Var_object,I)
			Stat=RecordCalcToggle(Var_record,On_off_sw)
		NEXT I
	CASE "ON","OFF","S","SWITCH"
	    Num_records= VObjectCount(Var_object)
	    FOR I=1 TO Num_records
		Var_record= VObjectRecord(Var_object,I)
		IF (ValidGeometry(Var_record)) THEN 
			SELECT UPC$(Answer$)
			CASE "ON"
				Stat= RecordCalcToggle(Var_record,WsTrue)
			CASE "OFF"
				Stat= RecordCalcToggle(Var_record,WsFalse)
			CASE "S","SWITCH"
				On_off= IsRecordCalcsOn(Var_record)
				IF On_off=WsTrue THEN
				    Stat=RecordCalcToggle(Var_record,WsFalse)
				ELSE
				    Stat=RecordCalcToggle(Var_record,WsTrue)
				END IF
			END SELECT
		END IF
	    NEXT I
	CASE ELSE
		ON ERROR GOTO Get_record
		Answer$=TRIM$(Answer$)
		Var_record= VObjectRecord(Var_object,VAL(Answer$))
		OFF ERROR
		IF (ValidGeometry(Var_record)) THEN
			On_off= IsRecordCalcsOn(Var_record)
			IF On_off=WsTrue THEN
			    Stat=RecordCalcToggle(Var_record,WsFalse)
			ELSE
			    Stat=RecordCalcToggle(Var_record,WsTrue)
			END IF
		END IF
	END SELECT
ELSE
Get_record: OFF ERROR
	IF NOT ValidGeometry(E1) THEN Pick_record
	Var_record=VarRecordParent(E1)
	IF NOT ValidGeometry(Var_record) THEN Pick_record
	Stat=Highlight(Var_record,Highlight_color,0)
	Stat= RecordCalcToggle(Var_record,WsTrue)
END IF

GOTO Pick_record

Leave:!
Stat=VarObjectName(Curr_obj,Object_name$)
Vstat=OpenVarObject(Object_name$)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

