
! script name: vthread.d/thrdembedonoff
! var_topic: switch status of embedded thread records

!A
!A NAME:
!A
!A 	Embed Thread Records on/off     VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will find records that have EMBED THREAD: in the description
!A	and list those records with their on/off status.  Then the user can
!A	switch the status of whatever record they want to change.
!A
!B INSTRUCTIONS:
!B
!B 	PICK RECORD TO SWITCH: Pick the record
!B 		to be switched.  The record CANNOT be picked
!B 		graphically.  Only from the list.
!B
!B NOTES: 
!B
!B	This function will not work on merged records unless the description
!B	contains the EMBED THREAD: marker.
!B
!# see also - vthread.d/thread.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: change embed thread record status")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM File$[256]
DIM Title$[256]
DIM A$[256]
DIM Onoff$[256]
DIM Namelist$[32000],List_str$[256]
DIM Feat_desc$[256]

On_color=4
Off_color=2
File$="tempdata"

DeActivateUndo
Start:!
! Record_group= SearchRecordDescr(Search1$,True= Match Partial,True= Remove Dups)

Group= SearchRecordDescr("EMBED THREAD:",WsTrue,WsFalse)
IF NOT ValidGeometry(Group) THEN Leave

Namelist$= ""
Num_recs= GroupCount(Group)
FOR I= 1 TO Num_recs
        Op_record= GroupElement(Group,I)
        Stat= GetDescription(Op_record,Feat_desc$)
        J= POS(Feat_desc$,":")
	Onoff= IsRecordCalcsOn(Op_record)
	IF OnOff=WsTrue THEN
		OnOff$= "  ON  "
	ELSE
		OnOff$= " OFF  "
	END IF
	OUTPUT A$ USING "A,3D,#,K"; "#",I
        Namelist$= Namelist$&A$&OnOff$&Feat_desc$[J+1]&","
NEXT I

Ask_ques:Stat=GeneralListBox("EMBED THREAD","Record Chosen",Namelist$)
Stat= SetInputFormat("a99","")
Stat= GetValue("CHOOSE RECORD TO SWITCH,   All ",Answer$)
IF ExitScript(Destination$) OR Answer$="CANCEL" THEN Leave
SELECT Answer$
CASE "All", "A", "a", "ALL"
	GOTO Toggle_all
END SELECT
FOR K= 1 TO Num_recs
	Stat= StringFieldStr(Namelist$,",",K,List_str$)
	IF List_str$= Answer$ THEN Pick_record
NEXT K
GOTO Ask_ques


Pick_record:!
Var_record= GroupElement(Group,K)
IF POS(List_str$," OFF  ") THEN
	Stat= RecordCalcToggle(Var_record,WsTrue)
ELSE
	Stat= RecordCalcToggle(Var_record,WsFalse)
END IF
Stat= DeleteEntity(Group)
GOTO Start

Toggle_all:!
        Num_recs= GroupCount(Group)
        FOR I= 1 TO Num_recs
                Var_record= GroupElement(Group,I)
                Onoff= IsRecordCalcsOn(Var_record)
                IF OnOff=WsTrue THEN
                        Stat= RecordCalcToggle(Var_record,WsFalse)
                ELSE
                        Stat= RecordCalcToggle(Var_record,WsTrue)
                END IF
        NEXT I
Stat= DeleteEntity(Group)
GOTO Start

Leave:!
Stat= DeleteEntity(Group)
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
