
! script name: vcontrol.d/editrecord
! var_topic: edit variational record data

!A
!A NAME:
!A
!A 	Edit Variational Record Data
!A
!A DESCRIPTION:
!A
!A 	This script allows the user to edit the contents of a variational
!A 	record. The syntax of a variational record is identical to
!A 	the synergy scripting language. Only experienced script writers
!A 	should attempt to edit the record data. Make sure the file is
!A 	saved before using this function.
!A
!B INSTRUCTIONS:
!B
!B 	PICK VARIATIONAL RECORD,   Number: Pick the record to be edited.
!B
!B 	PICK VARIATIONAL OBJECT: Pick the VDM object containing the record to
!B 		be edited.  NOTE: This question is only asked if a record
!B 		number has been entered in response to the previous question.
!B
!B 	RECORD # IN OBJECT:   Object_name: Enter the VDM record number of the
!B 		selected VDM object.
!B
!# see also - htdocs/help.d/vdminfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: edit variational record data")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Object_name$[256]
DIM Descr$[256]
DIM File$[256]
DIM Data$[10000]
DIM Editor$[256]

Highlight_color=2
File$= "tempdata"
Stat= NamedVarStr("file editor",WsSystemVars,"notepad.exe",Editor$)
Flip_file= NamedVarVal("flip crlf",WsSystemVars,0)

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= VarRecordData(Var_record,Data$)

stat= OutputString(File$,Data$,WsNewFile)
Stat=EditFile(Editor$,File$,Flip_file)

Stat=SetInputFormat("a1",",R,C,")
Stat=GetValue("RECORD:   Replace , Cancel",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat=SetInputFormat("n4","")
IF Answer$= "R" THEN
	Stat= ReadToString(File$,Data$)
	IF LEN(Data$)> 1 THEN
		Stat= ReplaceRecordData(Var_record,Data$)
	END IF
END IF

GOTO 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$)
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
