
! script name: vnvars.d/varsubtype
! var_topic: add description to variable

!A
!A NAME:
!A
!A 	Change Subtype
!A
!A DESCRIPTION:
!A
!A 	This script allows the user to change or add a variable subtype
!A	to an independent variable.
!A
!B INSTRUCTIONS:
!B
!B 	NAME OF VARIABLE: Pick the variable from the selection box.	
!B
!B 	VARIABLE DESCRIPTION, None: Input the description to be applied
!B 		to the variable. None will cancel any existing description.
!B
!B	TYPE OF VARIABLE: Choose the category of the variable.
!B
!B	TYPE OF SWITCH: Describe the variables switch type.
!B
!B	CHOOSE GEOMETRY TYPE: Choose the geometry attribute to use for the
!B		variable subtype.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: change variable subtype")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Namelist$[4096]

DeActivateUndo
Generation= 3
Highlight_color=2
Start:!

Stat=UserSelectBox("VARIABLES","selected variable",WsVariationVars,WsVarSelect)
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("NAME OF VARIABLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF (Answer$="CANCEL") THEN Leave

N=POS(Answer$,"=")
IF (N>1) THEN
	Answer$=Answer$[1,N-1]
	Answer$=TRIM$(Answer$)
END IF

Name$=Answer$
Edit_var=FindNamedVar(Name$,WsVariationVars)
IF NOT ValidGeometry(Edit_var) THEN Start
Var_subtype= GetVarSubtype(Edit_var)

Type_ques:Namelist$= "Switch,Geometry attribute,Directory,File"
Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
Stat=SetInputFormat("a99=","")
SELECT Var_subtype
CASE WsNVTypeOnOff,WsNVTypeYesNo,WsNVTypeTrueFalse,WsNVTypeFwdRev,WsNVTypeLeftRight
	Stat= SetEqualsValue(0,"Switch")
CASE WsNVTypeDiameter,WsNVTypeRadius,WsNVTypeDepth,WsNVTypeAngle
	Stat= SetEqualsValue(0,"Geometry attribute")
CASE WsNVTypeDir
	Stat= SetEqualsValue(0,"Directory")
CASE WsNVTypeFilePath
	Stat= SetEqualsValue(0,"File")
END SELECT
Stat=GetValue("TYPE OF VARIABLE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Start
SELECT UPC$(Answer$)
CASE "SWITCH"
Sw_ques:Stat=SetInputFormat("a99=","")
	Namelist$= "On/off,Yes/no,True/false,Forward/reverse,Left/right"
	Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
	SELECT Var_subtype
		CASE WsNVTypeOnOff
			Stat= SetEqualsValue(0,"On/off")
		CASE WsNVTypeYesNo
			Stat= SetEqualsValue(0,"Yes/no")
		CASE WsNVTypeTrueFalse
			Stat= SetEqualsValue(0,"True/false")
		CASE WsNVTypeFwdRev
			Stat= SetEqualsValue(0,"Forward/reverse")
		CASE WsNVTypeLeftRight
			Stat= SetEqualsValue(0,"Left/right")
	END SELECT
	Stat=GetValue("TYPE OF SWITCH",Answer$)
	IF ExitScript(Destination$) THEN Leave
	LowerSelectBox
	SELECT UPC$(Answer$)
	CASE "ON/OFF"
		V_type= WsNVTypeOnOff
	CASE "YES/NO"
		V_type= WsNVTypeYesNo
	CASE "TRUE/FALSE"
		V_type= WsNVTypeTrueFalse
	CASE "FORWARD/REVERSE"
		V_type= WsNVTypeFwdRev
	CASE "LEFT/RIGHT"
		V_type= WsNVTypeLeftRight
	CASE "CANCEL"
		GOTO Type_ques
	CASE ELSE
		GOTO Sw_ques
	END SELECT
	Stat=SetVarSubtype(Edit_var,V_type)
CASE "GEOMETRY ATTRIBUTE"
Geom_ques:Stat=SetInputFormat("a99=","")
	Namelist$= "Radius,Diameter,Angle,Depth"
	Stat=GeneralListBox("SELECTIONS","SELECTION",Namelist$)
	SELECT Var_subtype
		CASE WsNVTypeDiameter
			Stat= SetEqualsValue(0,"Diameter")
		CASE WsNVTypeRadius
			Stat= SetEqualsValue(0,"Radius")
		CASE WsNVTypeDepth
			Stat= SetEqualsValue(0,"Depth")
		CASE WsNVTypeAngle
			Stat= SetEqualsValue(0,"Angle")
	END SELECT
	Stat=GetValue("CHOOSE GEOMETRY TYPE",Answer$)
	IF ExitScript(Destination$) THEN Leave
	LowerSelectBox
	SELECT UPC$(Answer$)
	CASE "DIAMETER"
		V_type= WsNVTypeDiameter
	CASE "RADIUS"
		V_type= WsNVTypeRadius
	CASE "DEPTH"
		V_type= WsNVTypeDepth
	CASE "ANGLE"
		V_type= WsNVTypeAngle
	CASE "CANCEL"
		GOTO Type_ques
	CASE ELSE
		GOTO Geom_ques
	END SELECT
	Stat=SetVarSubtype(Edit_var,V_type)
CASE "DIRECTORY","DIR"
	Stat=SetVarSubtype(Edit_var,WsNVTypeDir)
CASE "FILE"
	Stat=SetVarSubtype(Edit_var,WsNVTypeFilePath)
END SELECT

GOTO Start

Leave:!

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