
! script name: vnvars.d/vformula
! var_topic: make formula variable

!A
!A NAME:
!A
!A 	Formula (make variable)
!A
!A DESCRIPTION:
!A
!A 	This script makes a variable dependent on a formula.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME: Enter the variable name.
!B
!B 	INVALID VARIABLE NAME: Name input was invalid choose new variable.
!B
!B 	VARIABLE VALUE: Type in the variable value as a formula.
!B 		For example:
!B
!B 			=(a+b)/2
!B 			=COS(Angle1+45)
!B
!B 		The equals sign in front tells the system that the input is
!B 		a formula involving named variables.  The variables a,b, and
!B 		Angle1 must have already been defined.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: make formula variable")

DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Var_val$[256]
DIM Destination$[256]
DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo
Name_loop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("VARIABLE NAME",Answer$)
IF ExitScript(Destination$) THEN Leave
Name$=Answer$
IF NOT ValidVariableName(Name$)	THEN
	Stat=SetInputFormat("a99","")
	Stat=GetValue("INVALID VARIABLE NAME, Proceed",Answer$)
	IF ExitScript(Destination$) THEN Leave
	GOTO Name_loop
END IF

Stat=SetInputFormat("n4","")
Value=GetValue("VARIABLE VALUE")
IF ExitScript(Destination$) THEN Leave
No_var=LastVariableInput(Var_val$)

RecordFunctionOn
Stat=RecordDescr("VARIABLE: Formula")
IF No_var THEN
	V1=NumericVariable(Name$,WsVariationVars,Value)
ELSE
	V1=NumericVariable(Name$,WsVariationVars,Var_val$)
	Stat=SetVariableDescr(V1,"Formula:  "&Var_val$)
END IF
RecordFunctionOff
CloseVarRecord

GOTO Name_loop

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

