
! script name: items.d/itemcount
! topic: Count number of occurrences of a similar item.

!A
!A NAME:
!A
!A 	Item Count
!A
!A DESCRIPTION:
!A
!A 	This script counts the number of times an item flag occurs in the
!A 	database.
!A
!# see also - htdocs/help.d/items.htm
!# see also - htdocs/help.d/property.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: item count ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM A$[256]
DIM B$[256]
DIM File$[256]
DIM File2$[256]

Start:!
File$= "tempdata"
Stat= RemoveFile(File$)

ItemCleanup
Group= UniqueItemsGrp
Stat= AlphabetizePropGrp(Group)
Stat=UserSelectBox("ITEMS","Item selected",0,WsPropGroupSelect,Group)

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

Num1= NumericPrefix(Name$)
IF NOT Num1 THEN Pick_prop
Element= GroupElement(Group,Num1)
IF NOT ValidGeometry(Element) THEN Start

Item_group= SimilarItemsGrp(Element)

Nitems= GroupCount(Item_group)

Stat= DeleteEntity(Item_group)

N1= POS(Name$,")")+1
IF N1< LEN(Name$) THEN
	Name$= Name$[N1]
END IF
A$= VAL$(Nitems)&"  "&Name$&CHR$(10)
stat= OutputString(File$,CHR$(10),WsNewFile)
stat= OutputString(File$,A$,WsAppend)
stat= OutputString(File$,CHR$(10),WsAppend)
Stat=MessageFileBox(File$,"ITEM LIST")


GOTO Pick_prop

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