
! script name: vitem.d/itemfieldentry
! var_topic: copy an item flag field into a table entry

!A
!A NAME:
!A
!A 	Item Field Table Entry
!A
!A DESCRIPTION:
!A
!A 	This script will take a data field from an item flag and place it in
!A 	a table.  This gives you easy access to the data that is contained in
!A 	the info packet.  You can use the table as a visual display of the
!A 	information contained in the item flag, you can manipulate the data
!A 	within Synergy, or you can export the table so that the data can be
!A 	used by a different program.  The data fields may be either string or
!A 	numeric. Numeric data will be treated as a numeric entry; String data
!A 	will be treated as a string entry. 
!A
!B INSTRUCTIONS:
!B
!B 	INPUT ITEM ID NAME: Pick the item from the selection box.
!B
!B 	SELECT DATA FIELD: Pick the data field from the selection box.
!B
!B 	PICK TABLE ENTRY POSITION: Pick the row column position in the table.
!B
!C NOTES:
!C
!C 	Be careful when using this function. It is possible to create a
!C 	dependency on an item flag that may not always be present. For example,
!C 	if an item flag is part of an embedded file, changing the embedded file
!C 	may remove the item flag. 
!C
!# see also - htdocs/help.d/property.htm

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

DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Table$[256]
DIM Descr$[256]
DIM Element$[256]
DIM Destination$[256]
DIM Prop_name$[256]
DIM Field$[256]
DIM List$[32000]
DIM Namelist$[32000]
DIM Field_id$[256]
DIM Field_data$[256]
DIM D_label$[256]
DIM Choice$[256]
DIM Format$[256]
DEG

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

A= GetDefault(WsPlacesAfter)
Format$= "decimal "&VAL$(A)

DeActivateUndo
Start:!

Namelist$=""
Item_group= UniqueItemsGrp
IF NOT GroupCount(Item_group) THEN Leave
Stat= AlphabetizePropGrp(Item_group)
Stat=UserSelectBox("ITEM FLAGS","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

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


List_fields:!
Namelist$= DataFieldListStr(Prop_ent,":",",",WsNoOrder,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

Pick_loop:!
stat= SetInputFormat("n4","")
Element1=PickEntity("PICK TABLE ENTRY POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(Element1,Table$)
R1=TableParaRow(Element1,T1)
C1=TableParaColumn(Element1,T1)

Make_entry:!
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$= "TABLE ENTRY: "&A$&":"&B$&":"&Field_id$
Stat= EntityNameCheck(Prop_ent,Prop_name$)

Stat= EraseEntity(Element1)
RecordFunctionOn
Stat= RecordDescr(Descr$)
V1= StringConstant(Field_id$)
V2= FreeParameter("Row",R1)
V3= FreeParameter("Column",C1)
IF Numeric_entry THEN
	V4= StringConstant(Format$)
	Stat= DataValIntoTable(Table$,Prop_name$,V1,V4,V2,V3)
ELSE
	Stat= DataStrIntoTable(Table$,Prop_name$,V1,V2,V3)
END IF
RecordFunctionOff
CloseVarRecord
Stat= PlotEntity(Element1)

GOTO List_fields



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