
! script name: vproperty.d/extprptyvars
! var_topic: make variables from external info packet fields

!A
!A NAME:
!A
!A 	Variables from All External Fields
!A
!A DESCRIPTION:
!A
!A 	An external info packet field is an info packet that is not currently 
!A 	being used as an info packet entity. It remains external to the program
!A 	as an ASCII data file.  This script assigns a dependent variable as the
!A 	value of each data field in an external property file.  Numeric data
!A 	becomes numeric variables. String data becomes string variables.  This
!A 	allows you to variationally reference data not currently being used by
!A 	the system.
!A
!B INSTRUCTIONS:
!B
!B 	BASE NAME: Enter the base name of the variables.
!B
!B 	ENTER INFO PACKET ID NAME: Choose the info packet you want referenced
!B 	from the selection box.
!B
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: external property field variables ")

DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM Name$[512]
DIM Descr$[512]
DIM Element$[512]
DIM Destination$[512]
DIM Filename$[512]
DIM Prop_name$[512]
DIM Prop_dir$[512]
DIM Class_dir$[512]
DIM Prop_file$[512]
DIM Field$[512]
DIM Prop_class$[512]
DIM Namelist$[32000]
DIM Field_id$[512]
DIM Field_data$[512]
DIM D_label$[512]
DIM Choice$[512]
DIM Current_dir$[512]
DIM Ques$[512]
DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Start:!
DeActivateUndo
Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Name_loop:!
stat= SetInputFormat("a99","")
Stat=GetValue("VARIABLE BASE 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
E1= FindNamedVar(Name$,WsVariationVars)
IF ValidGeometry(E1) THEN
        stat= SetInputFormat("a99","")
        Stat=GetValue("VARIABLE NAME IN USE, Proceed",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        GOTO Name_loop
END IF

Ask_class:!
D_label$="PACKET CLASSES"
Choice$="CLASS SELECTED"
Ques$= "PACKET CLASS DIRECTORY  List  "
Answer$= SelectDirectory(Prop_dir$,"*",Ques$,D_label$,Choice$,"",Current_dir$)
IF (ExitScript(Destination$)) THEN Leave
IF  Answer$= "CANCEL" THEN Leave
Answer$= TRIM$(Answer$)
Class_dir$= BaseNamePath(Answer$,Prop_dir$)
Prop_class$= PathNameFile(Answer$)

Ask_file:!
D_label$= Prop_class$
Choice$= Prop_class$&" SELECTED"
Stat= DirListBox(FileNameString(Prop_dir$,Class_dir$),"*",D_label$,Choice$,WsAscending)

File_name:stat= SetInputFormat("a99","")
stat= GetValue("PACKET FILE NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
IF NOT LEN(Answer$) THEN File_name
Prop_file$= Answer$
Filename$= FileNameString(Prop_dir$,Class_dir$,Prop_file$)
LowerSelectBox

Id_number=GetExtUserValue(Filename$,"Class id number:")
Prop_name$= ExtUserDataStr(Filename$,"Name:")
Prop_ent= ReadUserData(Id_number,Name$,Filename$)
A$= UserDataStr(Prop_ent,"Class name:")
B$= UserDataStr(Prop_ent,"Name:")
Descr$= "FIELD VARIABLES: "&A$&":"&B$&":"
Stat= DeleteEntity(Prop_ent)

RecordFunctionOn
Stat= RecordDescr(Descr$)
V2= StringConstant(Prop_dir$)
V3= StringConstant(Class_dir$)
V4= StringConstant(Prop_file$)
V5= StringConstant(FileNameString(V2,V3,V4))
V2=CreateVariable(Name$,WsVariationVars,VariableString(V5))
G1= ExtPropVariables(V5,EntityNameStr(V2),":",WsVariationVars)
Stat= DeleteEntity(G1)
RecordFunctionOff
CloseVarRecord

GOTO Start

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

