
! script name: amo.d/editquesvars
! var_topic: edit TurboPost amo variables

!A
!A NAME:
!A
!A 	Edit Amo Question Variables
!A
!A DESCRIPTION:
!A
!A 	This script edits the answers to any questions that were asked 
!A 	by running AMO.  The variables are changed for TurboPost on the
!A 	next AMO execution.
!A
!B INSTRUCTIONS:
!B
!B 	CHOOSE QUESTIONS TO EDIT: Pick the question packet
!B 		you want to edit.
!B
!B 	FIELD TO EDIT: Choose the TurboPost variable to edit.
!B 		DONE will go back to the previous question (as will CANCEL).
!B 		DELETE will give you the option to remove the stored
!B 		answers for that question file.
!B
!B 	DELETE THESE ANSWERS Yes or No:  You can delete the
!B 		saved answers.  This will allow you to re-answer
!B 		the questions upon execute.
!B
!B 	NEW VALUE FOR Field: Enter the changed value.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: edit amo question variables")

DIM Answer$[256],Destination$[256]
DIM Packet_data$[256],Packet_name$[256]
DIM Namelist$[32000],Field_id$[256]
DIM Varval$[256]

Ques_packet= 911

Start:!
Ques_grp= UserDataGroup(Ques_packet)
IF NOT ValidGeometry(Ques_grp) THEN Leave

Num_ques= GroupCount(Ques_grp)
IF NOT Num_ques THEN Leave
Namelist$= ""
FOR J= 1 TO Num_ques
	Ques_data= GroupElement(Ques_grp,J)
	Packet_name$= UserDataStr(Ques_data,"Name:")
	Packet_data$= UserDataStr(Ques_data,"Packet data:")
	IF Packet_data$="NONE" THEN Packet_data$=""
	Namelist$= Namelist$&VAL$(J)&")"&Packet_name$&"  "&Packet_data$&","
NEXT J
Namelist$= Namelist$&",,DELETE,"
Stat= GeneralListBox("QUESTIONS","SELECTION",Namelist$)
Stat= SetInputMinMax(1,Num_ques)
Stat= SetInputFormat("a99","")
Stat= GetValue("CHOOSE QUESTIONS TO EDIT",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "CANCEL" THEN Leave
IF Answer$= "DELETE" THEN
	Stat= DeleteGroup(Ques_grp,WsTrue)
	GOTO Leave
END IF
Stat= UnSetInputMinMax
Value= VAL(Answer$)
Ques_data= GroupElement(Ques_grp,Value)

Next_field:!
Ques_copy= CopyEntity(Ques_data)
Stat= DeleteUserField(Ques_copy,"Name:")
Stat= DeleteUserField(Ques_copy,"Packet data:")
Namelist$= DataFieldListStr(Ques_copy,":",",",NoOrder,WsTrue)
Namelist$= Namelist$&",DONE,DELETE,"
Stat= GeneralListBox("VARIABLES","SELECTION",Namelist$)
Stat= SetInputFormat("a99","")
Stat= GetValue("FIELD TO EDIT ",Answer$)
Exit_script= ExitScript(Destination$)
IF Exit_script OR Answer$="CANCEL" OR Answer$="DELETE" OR Answer$= "DONE" THEN
	IF Answer$= "DELETE" THEN
		LowerSelectBox
		Stat= SetInputFormat("a1",",Y,N,")
		Stat= GetValue("DELETE THESE ANSWERS Yes or No ",Answer$)
		IF Answer$= "Y" THEN
			Answer$= "DELETE"
		ELSE
			Answer$= ""
		END IF
	END IF
	Stat= DeleteEntity(Ques_copy)
	Stat= DeleteEntity(Ques_grp)
	IF Answer$= "DELETE" THEN Stat= DeleteEntity(Ques_data)
	IF Exit_script THEN
		GOTO Leave
	ELSE
		GOTO Start
	END IF
END IF

IF NOT POS(Answer$,"=") THEN
	Stat= DeleteEntity(Ques_copy)
	GOTO Next_field
END IF
Field_id$= DataFieldStr(Answer$,"=",1)
LowerSelectBox
Varval$= UserDataStr(Ques_data,Field_id$&":")
IF IsStringNumeric(Varval$) THEN
	Stat= SetEqualsValue(VAL(Varval$),"")
	Stat= SetInputFormat("n4=","")
	Value= GetValue("NEW VALUE FOR "&Field_id$)
	IF ExitScript(Destination$) THEN Leave
	Stat= PutUserValue(Ques_data,Field_id$&":",Value)
ELSE
	Stat= SetInputFormat("a99=","")
	Stat= SetEqualsValue(0,Varval$)
	Stat= GetValue("NEW VALUE FOR "&Field_id$,Answer$)
	IF ExitScript(Destination$) THEN Leave
	Stat= PutUserString(Ques_data,Field_id$&":",Answer$)
END IF
Stat= DeleteEntity(Ques_copy)

GOTO Next_field

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