
! script name: vproperty.d/propfieldvar
! var_topic: make a variable with a value from a info packet field

!A
!A NAME:
!A
!A 	Variable from a Field
!A
!A DESCRIPTION:
!A
!A 	This script assigns the values from an info packet data field to a
!A 	variable. This allows you to make practical use of the data that
!A 	resides in an info packet.  You can have Synergy draw the information
!A 	that it needs for various functions directly from your info packets. 
!A 	Numeric data becomes a numeric variable,  String data becomes a string
!A 	variable.
!A
!B INSTRUCTIONS:
!B
!B 	VARIABLE NAME:  Enter the name of the variable.
!B
!B 	ENTER INFO PACKET ID NAME: Enter the info packet from the selection box.
!B
!B 	SELECT DATA FIELD: Select the data field from the selection box.
!B
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: info packet field variable ")

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 Namelist$[32000]
DIM Field_id$[256]
DIM Field_data$[256]
DIM D_label$[256]
DIM Choice$[256]
DEG

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

Start:!
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

Existing_props:!
Namelist$=""
Group1= GrpOfUserProps
Group= DependentSubGroup(Group1)
Stat= DeleteEntity(Group1)
IF NOT GroupCount(Group) THEN Leave
Stat=UserSelectBox("EXISTING INFO PACKETS","Packet selected",0,WsPropGroupSelect,Group)

Pick_prop:!
Stat=SetInputFormat("a99","")
Stat=GetValue("ENTER INFO PACKET ID NAME",Prop_name$)
IF (ExitScript(Destination$)) THEN Leave
IF Prop_name$= "CANCEL" THEN Leave

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



List_fields:!
Namelist$= DataFieldListStr(Prop_ent,":",",",NoOrder,WsTrue)

D_label$="DATA FIELDS"
Choice$="DATA FIELD SELECTED"
Mask$="*"
Stat=GeneralListBox(D_label$,Choice$,Namelist$)

Data_field:stat= SetInputFormat("a99","")
stat= GetValue("SELECT DATA FIELD",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Data_field
LowerSelectBox
SELECT Answer$
CASE "CANCEL"
        GOTO Start
END SELECT
IF POS(Answer$,"=") THEN
        Field_id$= DataFieldStr(Answer$,"=",1)
	Field_id$= Field_id$&":"
        Field_data$= DataFieldStr(Answer$,"=",2)
        Field_data$= TRIM$(Field_data$)
	
ELSE
        Field_data$=""
END IF
GOTO Make_variable

Make_variable:!
IF IsStringNumeric(Field_data$) THEN
	Numeric_entry=1
ELSE
	Numeric_entry=0
END IF

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

RecordFunctionOn
Stat= RecordDescr(Descr$)
V1= StringConstant(Field_id$)
IF Numeric_entry THEN
        V3=NumericVariable(Name$,WsVariationVars,GetUserValue(Prop_name$,V1))
ELSE
        V3=CreateVariable(Name$,WsVariationVars,UserDataStr(Prop_name$,V1))
END IF
stat= SetVariableDescr(V3,"Property field")
RecordFunctionOff
CloseVarRecord

GOTO Start




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

