
! script name: vnvars.d/vindependent
! var_topic: make independent variable

!A
!A NAME:
!A
!A 	Independent (make variable)
!A
!A DESCRIPTION:
!A
!A 	This script allows an independent variable to be created.  Independent
!A 	variables are created with any value and are not dependent on existing
!A 	geometry.  Independent variables do not have a VDM record constraining
!A 	these values.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME: Enter the variable name to be used.
!B
!B 	INVALID VARIABLE NAME, Proceed: This message
!B 		will appear if a variable name is not allowed.
!B 		Proceed will return to the VARIABLE NAME question.
!B
!B 	VARIABLE VALUE: Enter the value for the variable.
!B
!C NOTES:
!C
!C 	Variables need to have a unique name assigned to them, a maximum
!C 	length of 18 characters, and should be a combination of letters,
!C 	numbers, and underbars.  Variable names should not start with an
!C 	underbar.  Variable names may not be the same as any SYNERGY keywords.
!C 	Variable names may never have a space in it and should not contain
!C 	any characters other than letters, numbers, and underbars.
!C
!C 	A recommended naming convention is to use a combination of letters
!C 	and numbers or underbars.  For example: A1, R1, and Line1 are acceptable
!C 	variable names.  If this convention is followed, a SYNERGY keyword
!C 	is less likely to be accidentally used.
!C
!C 	There is a description option available for variables.  If a name is
!C 	not descriptive enough, it is recommended that this option be used.
!C

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

DIM Answer$[256],Destination$[256]
DIM Name$[256],Descr$[256]
DIM A$[256],Namelist$[4096]
DEG

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

Input_value:Stat=SetInputFormat("n4a1",",S,T,")
Value=GetValue("VARIABLE VALUE, String, Type ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="S" THEN String_ques
IF Answer$<>"T" THEN
	V1=CreateVariable(Name$,WsVariationVars,Value)
ELSE
Type_ques:Namelist$= "Numeric,String,Switch,Geometry attribute,Directory,File"
	Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
	Stat=SetInputFormat("a99","")
	Stat=GetValue("TYPE OF VARIABLE",Answer$)
	IF ExitScript(Destination$) THEN Leave
	SELECT UPC$(Answer$)
	CASE "CANCEL"
		GOTO Name_loop
	CASE "NUMERIC"
		GOTO Input_value
	CASE "STRING"
String_ques:	Stat=SetInputFormat("a99","")
		Stat=GetValue("STRING FOR "&Name$,Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF NOT LEN(Answer$) THEN Input_value
		Stat= BackSlashChars(Answer$,A$)
		Stat= ReplaceString(A$,"\n",CHR$(10),Answer$)
		V1=CreateVariable(Name$,WsVariationVars,Answer$)
	CASE "SWITCH"
Sw_ques:	Stat=SetInputFormat("a99","")
		Namelist$= "On/off,Yes/no,True/false,Forward/reverse,Left/right"
		Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
		Stat=GetValue("TYPE OF SWITCH",Answer$)
		IF ExitScript(Destination$) THEN Leave
		LowerSelectBox
		SELECT UPC$(Answer$)
		CASE "ON/OFF"
			Stat= SetInputFormat("a99=","")
			Stat= SetEqualsValue(0,"On")
			Stat= GetValue(Name$&": On or Off ",Answer$)
			A= (UPC$(Answer$)="ON")
			V_type= WsNVTypeOnOff
		CASE "YES/NO"
			Stat= SetInputFormat("a1=",",Y,N,")
			Stat= SetEqualsValue(0,"Y")
			Stat= GetValue(Name$&": Yes or No",Answer$)
			A= (Answer$="Y")
			V_type= WsNVTypeYesNo
		CASE "TRUE/FALSE"
			Stat= SetInputFormat("a1=",",T,F,")
			Stat= SetEqualsValue(0,"T")
			Stat= GetValue(Name$&": True or False",Answer$)
			A= (Answer$="T")
			V_type= WsNVTypeTrueFalse
		CASE "LEFT/RIGHT"
			Stat= SetInputFormat("a1=",",L,R,")
			Stat= SetEqualsValue(0,"L")
			Stat= GetValue(Name$&": Left or Right",Answer$)
			IF (Answer$="R") THEN
				A= WsRight
			ELSE
				A= WsLeft
			END IF
			V_type= WsNVTypeLeftRight
		CASE "FORWARD/REVERSE"
			Stat= SetInputFormat("a1=",",F,R,")
			Stat= SetEqualsValue(0,"F")
			Stat= GetValue(Name$&": Forward or Reverse",Answer$)
			IF (Answer$="R") THEN
				A= WsReverse
			ELSE
				A= WsForward
			END IF
			V_type= WsNVTypeFwdRev
		CASE "CANCEL"
			GOTO Type_ques
		CASE ELSE
			GOTO Sw_ques
		END SELECT
		IF ExitScript(Destination$) THEN Leave
		V1=CreateVariable(Name$,WsVariationVars,A)
		Stat=SetVarSubtype(V1,V_type)
	CASE "GEOMETRY ATTRIBUTE"
Geom_ques:	Stat=SetInputFormat("a99","")
		Namelist$= "Radius,Diameter,Angle,Depth"
		Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
		Stat=GetValue("CHOOSE GEOMETRY TYPE",Answer$)
		IF ExitScript(Destination$) THEN Leave
		LowerSelectBox
		SELECT UPC$(Answer$)
		CASE "DIAMETER"
			Stat=SetRadiusEquals(A/2)
			A=InputRadius("INPUT "&Name$,WsDiaInput)
			V_type= WsNVTypeDiameter
		CASE "RADIUS"
			Stat=SetRadiusEquals(A)
			A=InputRadius("INPUT "&Name$)
			V_type= WsNVTypeRadius
		CASE "DEPTH"
			Stat=SetDepthEquals(A)
			A=InputDepth("INPUT "&Name$)
			V_type= WsNVTypeDepth
		CASE "ANGLE"
			Stat=SetAngleEquals(A)
			A=InputAngle("INPUT "&Name$)
			V_type= WsNVTypeAngle
		CASE "CANCEL"
			GOTO Type_ques
		CASE ELSE
			GOTO Geom_ques
		END SELECT
		IF ExitScript(Destination$) THEN Leave
		V1=CreateVariable(Name$,WsVariationVars,A)
		Stat=SetVarSubtype(V1,V_type)
	CASE "DIRECTORY","DIR"
		Stat= DisplayMessage("INPUT "&Name$)
		Stat= SetInputFormat("a99","")
		Stat= UserDirSelectBox("","DIRECTORIES")
                Stat= GetValue("",Answer$)
                IF Answer$="CANCEL" THEN Type_ques
		Stat= BackSlashChars(Answer$,A$)
		Stat= ReplaceString(A$,"\n",CHR$(10),Answer$)
		V1= CreateVariable(Name$,WsVariationVars,Answer$)
		Stat=SetVarSubtype(V1,WsNVTypeDir)
	CASE "FILE"
		Stat= DisplayMessage("INPUT "&Name$)
		Stat= UserFileBox("/usr/weber","*","DIR","DIRS","FILES","FILE","")
		Stat= SetInputFormat("a99","")
                Stat= GetValue("",Answer$)
                IF Answer$="CANCEL" THEN Type_ques
		Stat= BackSlashChars(Answer$,A$)
		Stat= ReplaceString(A$,"\n",CHR$(10),Answer$)
		V1= CreateVariable(Name$,WsVariationVars,Answer$)
		Stat=SetVarSubtype(V1,WsNVTypeFilePath)
	END SELECT
END IF
Stat= SetActiveEnt(V1,WsTrue)

GOTO Name_loop

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

