
! script name: vlogic.d/truefalserec
! var_topic: make a record true false conditional

!A
!A NAME:
!A
!A 	True/False Record
!A
!A DESCRIPTION:
!A
!A 	This script allows the user to apply a true false condition 
!A 	(IF Variable=WsTrue THEN record     test) to the execution
!A 	of an existing record or records.
!A
!B INSTRUCTIONS:
!B
!B	If (test variable)= true THEN: Variable to
!B 		be set to true or false.
!B
!B 	PICK VARIATIONAL RECORD: Pick the record
!B 		to be made conditional.
!B
!B NOTES:
!B
!B 	The record data is modified to add the condition to the code.
!B
!B 	Once a record has been made conditional the only way it can be
!B 	returned to its original state is by editing the record data.
!B
!B 	The user should be cautious not to unintentionally apply
!B 	this function multipletimes to the same record.
!B
!B 	Different conditions may be applied to the same record.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: make a true false record")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Object_name$[256]
DIM Descr$[256]
DIM Data$[32000]
DIM Newdata$[32000]
DIM True_name$[256]
DIM Relation$[256]
DIM A$[256]
DIM Quote$[10]
DIM Lf$[10]
DEG


DeActivateUndo
Highlight_color=2
Pick_by_number=0
Var_object=0

Quote$= CHR$(34)
Lf$= CHR$(10)

Start:!
Stat=UserSelectBox("VARIABLES","selected variable",WsVariationVars,WsVarSelect)
IF Stat=1 THEN Leave

True_var:Stat=SetInputFormat("a99","")
Stat=GetValue("IF (pick test variable)= true  THEN ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "CANCEL" THEN Leave
N=POS(Answer$,"=")
IF N>1 THEN
        Answer$=Answer$[1,N-1]
        Answer$=TRIM$(Answer$)
END IF
True_name$=Answer$
V1=FindNamedVar(True_name$,WsVariationVars)
IF NOT ValidGeometry(V1) THEN True_var

LowerSelectBox

Pick_record:!
IF Pick_by_number THEN
        GOSUB Record_number
ELSE
        Stat=SetInputFormat("a1",",N,E,")
        E1=PickEntity("PICK VARIATIONAL RECORD,   Number, Exit ",Answer$)
        IF ExitScript(Destination$) THEN Leave
        SELECT Answer$
        CASE "E"
                GOTO Leave
        CASE "N"
                Pick_by_number=1
                GOTO Pick_record
        END SELECT
        IF NOT ValidGeometry(E1) THEN Pick_record
        Var_record=VarRecordParent(E1)
        IF NOT ValidGeometry(Var_record) THEN Pick_record
        Var_object=VarObjectParent(E1)
        IF NOT ValidGeometry(Var_object) THEN Pick_record
END IF
IF NOT ValidGeometry(Var_record) THEN Pick_record
IF NOT ValidGeometry(Var_object) THEN Pick_record
Stat=VarObjectName(Var_object,Object_name$)
Stat=Highlight(Var_record,Highlight_color,0)
Stat=GetDescription(Var_record,Descr$)
Stat= VarRecordData(Var_record,Data$)

Newdata$= "A = NamedVarVal("&Quote$&True_name$&Quote$&",WsVariationVars,0.0)"&Lf$
Newdata$= Newdata$&"IF A THEN "&Lf$
Newdata$= Newdata$&Data$
Newdata$= Newdata$&"END IF"&Lf$

Stat=Highlight(Var_record,Highlight_color,0)
Stat=SetInputFormat("a1=",",Y,N,")
Stat= SetEqualsValue(0,"Y")
Stat=GetValue("MAKE CONDITIONAL Yes or No  ",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat=SetInputFormat("n4","")
IF Answer$= "Y" THEN
IF LEN(Newdata$)> 1 THEN
	Stat= ReplaceRecordData(Var_record,Newdata$)
END IF
END IF

GOTO Pick_record

Record_number:!
IF NOT ValidGeometry(Var_object) THEN
        GOSUB Pick_object
END IF
Stat=SetInputFormat("n0a1",",P,N,")
Rec_number=GetValue("RECORD # IN OBJECT: "&Object_name$&" , Pick, New Object ",Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "P"
        Pick_by_number=0
        GOTO Pick_record
CASE "N"
        GOSUB Pick_object
        GOTO Record_number
END SELECT
Var_record=VObjectRecord(Var_object,Rec_number)
IF NOT ValidGeometry(Var_record) THEN Record_number
Pick_by_number=1
RETURN

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

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