
! script name: vitems.d/itemvars
! var_topic: make variables from item flag fields

!A
!A NAME:
!A
!A 	Make variables from item flag fields	---VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script assigns a dependent variable to the value of each data
!A 	field in an item flag entity.  Numeric data becomes numeric variables.
!A 	String data becomes string variables.
!A
!B INSTRUCTIONS:
!B
!B 	BASE NAME: Give the base name of the variables.
!B
!B 	INPUT ITEM ID NAME: Pick the item flag from the selection box.
!B
!C NOTES:
!C
!C 	Be careful not to create a dependency with an item flag that may not
!C 	always be present.  For example, an item flag may be part of an
!C 	embedded file.  Removing the item from the embedded file will remove
!C 	the item from the current file.
!C
!# see also - htdocs/help.d/property.htm
!# see also - item.d/item.hlp

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

DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DIM Prop_name$[256]
DIM Field$[256]
DIM Field_id$[256]
DIM Field_data$[256]
DIM D_label$[256]
DIM Choice$[256]
DEG

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

DeActivateUndo
Start:!

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

Item_group= UniqueItemsGrp
Stat= AlphabetizePropGrp(Item_group)
IF NOT GroupCount(Item_group) THEN Leave
Stat=UserSelectBox("ITEMS","Item selected",0,WsPropGroupSelect,Item_group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT ITEM ID NAME",Prop_name$)
IF (ExitScript(Destination$)) THEN Leave
IF Prop_name$= "CANCEL" THEN Leave
LowerSelectBox

Num1= NumericPrefix(Prop_name$)
IF NOT Num1 THEN Pick_prop
Prop_ent= GroupElement(Item_group,Num1)
IF NOT ValidDependency(Prop_ent) THEN Pick_prop
Stat= EntityNameCheck(Prop_ent,Prop_name$)
Stat= DeleteEntity(Item_group)



A$= UserDataStr(Prop_ent,"Class name:")
B$=UserDataStr(Prop_ent,"Name:")
Descr$= "FIELD VARIABLES: "&A$&":"&B$&":"

RecordFunctionOn
Stat= RecordDescr(Descr$)
V1= StringConstant("Name:")
V2=CreateVariable(Name$,WsVariationVars,UserDataStr(Prop_name$,V1))
G1= PropertyVariables(Prop_name$,EntityNameStr(V2),":",WsVariationVars)
Stat= DeleteEntity(G1)
RecordFunctionOff
CloseVarRecord

GOTO Start




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