
! script name: vedit.d/replaceconst
! var_topic: replace variable reference

!A
!A NAME:
!A
!A 	Replace Constant Reference
!A
!A DESCRIPTION:
!A
!A 	This script allows a reference to a constant in a VDM record to be
!A 	replaced with another constant.
!A
!B INSTRUCTIONS:
!B
!B 	PICK VARIATIONAL RECORD,   Number: Pick the
!B 		record containing the constant to be changed.
!B
!B 		N - Enter "N" to allow the VDM record number to be entered.
!B
!B 	PICK VARIATIONAL OBJECT: Pick the VDM
!B 		object containing the constant to be changed.
!B 		NOTE: This question is only asked if a record number
!B 		has been entered in response to the previous question.
!B
!B 	RECORD # IN OBJECT:  object_name: Enter the
!B 		VDM record number of the selected VDM object.
!B
!B 	CONSTANT TO BE REPLACED: Select the constant
!B 		to be replaced from the select box.
!B
!B 	REPLACEMENT CONSTANT: Enter the value
!B 		of the replacement constant.
!B
!# see also - htdocs/help.d/vdminfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: replace constant")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Object_name$[256]
DIM Newname$[256]
DIM Descr$[256]
DIM Varstr$[256]
DIM Entities$[5000]
DIM Variables$[5000]
DIM Constants$[5000]

Stat=LineNumberIncr(1)
Highlight_color=2
Start_obj=0
Quote$=CHR$(34)

DeActivateUndo
Start:!
Pick_record:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK VARIATIONAL RECORD,   Number",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
	GOSUB Pick_object
Record_number:!
	Stat=SetInputFormat("n0","")
	Rec_number=GetValue("RECORD # IN OBJECT: "&Object_name$&"   ")
	IF ExitScript(Destination$) THEN Leave
	Var_record=VObjectRecord(Var_object,Rec_number)
	IF NOT ValidGeometry(Var_record) THEN Record_number
ELSE
	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

Stat=GetDescription(Var_record,Descr$)
Stat=VRecordNameList(Var_record,Entities$,Variables$,Constants$)
A=POS(Constants$,",")
IF A<LEN(Constants$) THEN
	Constants$=Constants$[A+1]
ELSE
	Constants$=""
END IF

IF LEN(Constants$)=0 THEN Pick_record

Stat=GeneralListBox(Descr$,"Constants",Constants$)

Stat=SetInputFormat("a99","")
Stat=GetValue("CONSTANT TO BE REPLACED",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Leave
Answer$=TRIM$(Answer$)
Name$=Answer$

LowerSelectBox

ON ERROR GOTO Pick_record
Para_value=VAL(Name$)

Replace_ques: Stat=SetEqualsValue(para_value)
Stat=SetInputFormat("n4=","")
Replace_value=GetValue("REPLACEMENT CONSTANT "&"  ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Pick_record
No_var=LastVariableInput(Varstr$)
IF No_var THEN
	Newname$=VAL$(Replace_value)
ELSE
	Newname$=Quote$&Varstr$&Quote$
END IF

PRINT Newname$
Stat=ReplaceConstant(Var_record,Name$,Newname$)

Stat= CleanNonVarGrps
Output_script=0
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputAllObjects("tempscript","vedit.d/replaceconst",Start_obj,Output_script)
IF Stat=1 THEN Start

LOAD "tempscript"

GOTO Raise_box

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:!

LowerSelectBox

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
