
! script name: property.d/makeuserprop
! topic: make an info packet

!A
!A NAME:
!A
!A 	Make a datastring info packet
!A
!A DESCRIPTION:
!A
!A 	This script creates a datastring which can be used as an info packet.
!A
!B INSTRUCTIONS:
!B
!B 	PACKET CLASS NAME: Select the name of the packet's class. All packets
!B 	in the same class directory should have the same class name.
!B
!B 	CLASS ID NUMBER  (10000 - 100000): Select a class ID number
!B 	(from 10000 to 100000).  A unique number must be assigned to
!B 	each packet class. Each packet in the class must have the same
!B 	class number. Each class must have a unique ID number.  Only
!B 	one packet of a specific class number can be associated
!B 	with a Synergy entity, however, many packets of different
!B 	classes may be associated with the same entity.
!B
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: make info packet ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Ent_Name$[256]
DIM Class_name$[256]
DIM Field$[256]
DIM Value$[256]
DIM Data$[32000]
DIM Field_names$(50)[256]
DIM Field_values$(50)[256]


DeActivateUndo
Start:!

Ask_class:stat= SetInputFormat("a99","")
stat= GetValue("PACKET CLASS NAME ",Class_name$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Class_name$) THEN Ask_class

Ask_id_num:stat= SetInputFormat("n0","")
Id_number= GetValue("PACKET CLASS ID NUMBER  (10000 - 100000) ")
IF (ExitScript(Destination$)) THEN Leave
IF Id_number< 10000 OR Id_number> 100000 THEN Ask_id_num

Ask_name:stat= SetInputFormat("a99","")
stat= GetValue("PACKET NAME ",Name$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Name$) THEN Ask_name


Nfields= 0

Field_loop:!
stat= SetInputFormat("a99","")
stat= GetValue("DATA FIELD NAME,  Proceed  ",Field$)
IF (ExitScript(Destination$)) THEN Leave
Field$= TRIM$(Field$)
SELECT Field$
CASE "P", "p", "Proceed","PROCEED"
	GOTO Make_property
END SELECT
IF NOT LEN(Field$) THEN Field_loop

stat= SetInputFormat("a99","")
stat= GetValue("DATA VALUE ",Value$)
IF (ExitScript(Destination$)) THEN Leave

Nfields= Nfields+1
Field_names$(Nfields)= Field$&":"
Field_values$(Nfields)= Value$
GOTO Field_loop


Make_property:!
E1= CreateUserData(Id_number,Name$,CHR$(10))
Stat= PutUserString(E1,"Class name:",Class_name$)
Stat= PutUserValue(E1,"Class id number:",Id_number)
Stat= PutUserString(E1,"Name:",Name$)
FOR I= 1 TO Nfields
	Field$= Field_names$(I)
	Value$= Field_values$(I)
	Stat= PutUserString(E1,Field$,Value$)
NEXT I
Data$= UserData(E1)
Stat= MessageStringBox(Data$,"User property: "&Name$)

GOTO Start

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


