
! script name: vproperty.d/fieldintotable
! var_topic: copy an info packet field into a table entry

!A
!A NAME:
!A
!A 	Entry from Packet Field
!A
!A DESCRIPTION:
!A
!A 	This script will take a data field in an info packet and place it in a
!A 	table entry position.  The data fields may either be string or numeric.
!A 	Numeric data becomes numeric table entries.  String data becomes string
!A 	entries.  You can use the table as a visual display of the information
!A 	contained in the info packet, you can manipulate the data within
!A 	Synergy, or you can export the table so that the data can be used by
!A 	a different program. 
!A
!B INSTRUCTIONS:
!B
!B 	ENTER INFO PACKET ID NAME: Select the info packet from the selection
!B 	box.
!B
!B 	SELECT DATA FIELD: Pick the data field from the selection box.
!B
!B 	PICK TABLE ENTRY POSITION: Enter the row column position in the table.
!B
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: info packet 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 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)

Start:!
DeActivateUndo

Existing_props:!
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,":",",",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= 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(Group)
Stat= DeleteEntity(Group1)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

