
! script name: vnvars.d/vrangeselect
! var_topic: make select case range variable 

!A
!A NAME:
!A
!A 	Relational: Select Range
!A
!A DESCRIPTION:
!A
!A 	This script makes a numeric variable that is set by select case,
!A 	dependent on ranges.
!A
!A 	SELECT A
!A 	CASE 0 TO 1
!A 		B= Value1
!A 	CASE 1 TO 2
!A 		B= Value2
!A 	CASE 2 TO 3
!A 		B= Value3
!A 	...
!A 	...
!A 	...
!A 	END SELECT
!A
!B INSTRUCTIONS:
!B
!B      This function sets up the basic commands for a
!B      variable value to be determined by a SELECT statement.
!B      The complexity of the SELECT statement requires that
!B      the data be entered in an ascii format rather than as
!B      a question answer format.
!B      Generic data is displayed in a text editor and the user
!B      modifies the data for a specific case.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: make select case range variable")

DIM Answer$[256]
DIM Name$[256]
DIM Name1$[256]
DIM Select_name$[256]
DIM A$[256]
DIM Descr$[256]
DIM File$[256]
DIM Data$[32000]
DIM Destination$[256]
DIM Editor$[256]
DEG


File$= "tempdata"
Stat= NamedVarStr("file editor",WsSystemVars,"notepad.exe",Editor$)
Flip_file= NamedVarVal("flip crlf",WsSystemVars,0)
Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo
Start:!
Name_loop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("NEW 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

Select_name$= "Selection_variable"
V1=NumericVariable(Select_name$,WsVariationVars,0.0)
Select_name$= CHR$(34)&Select_name$&CHR$(34)
Name1$= CHR$(34)&Name$&CHR$(34)

RecordFunctionOn
Stat=RecordDescr("VARIABLE: Select case")
Stat= PrintToVarRecord("A = NamedVarVal("&Select_name$&",WsVariationVars,0.0)")
Stat= PrintToVarRecord("SELECT A")
Stat= PrintToVarRecord("CASE 0 TO 1 ")
Stat= PrintToVarRecord("     Value= 0.0")
Stat= PrintToVarRecord("CASE 1 TO 2 ")
Stat= PrintToVarRecord("     Value= 0.5")
Stat= PrintToVarRecord("CASE 2 TO 3 ")
Stat= PrintToVarRecord("     Value= 1.0")
Stat= PrintToVarRecord("CASE ELSE")
Stat= PrintToVarRecord("     Value= 1.5")
Stat= PrintToVarRecord("END SELECT")
Stat= PrintToVarRecord("V1 = NumericVariable("&Name1$&",WsVariationVars,Value)")
RecordFunctionOff
Var_record= CurrentVarRecord
CloseVarRecord
V1=NumericVariable(Name$,WsVariationVars,Value)

Stat=GetDescription(Var_record,Descr$)
Stat= VarRecordData(Var_record,Data$)
stat= OutputString(File$,Data$,WsNewFile)
Stat=EditFile(Editor$,File$,Flip_file)

Stat=SetInputFormat("a1",",A,D,")
Stat=GetValue("RECORD:   Accept , Discard",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat=SetInputFormat("n4","")
IF Answer$= "D" THEN
	Stat=DeleteEntity(Var_record)
	GOTO Leave
END IF
IF Answer$= "A" THEN
        Stat= ReadToString(File$,Data$)
        IF LEN(Data$)> 1 THEN
                Stat= ReplaceRecordData(Var_record,Data$)
        END IF
END IF

GOTO Start

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

