FindImageItem and FindImageItemUp (Stringlist functions)
Find next/previous matching image item in Stringlist (Stringlist class)
Both these methods locate a Stringlist item that exactly matches the contents of an image item (or of a value converted to the image item format at the offset and length of the image item). The difference between FindImageItem and FindImageItemUp is the direction of the search: FindImageItem searches from the starting point in ascending item number order, while FindImageItemUp searches in descending item number order.
Both FindImageItem and FindImageItemUp accept four arguments, and they return the item number of the Stringlist item that matches the image item, or they return a 0 indicating that the item was not found. All other errors cause the request to be canceled.
%number = sl:FindImageItem( imageItem, [searchValue], [startItem], [operator])
%number = sl:FindImageItemUp( imageItem, [searchValue], [startItem], - [operator])
|%number||A numeric variable that is set to the number of the first item in the Stringlist that matches the search criterion, or it is set to 0 if no Stringlist items matched the search criterion.|
|sl||A Stringlist object.|
|imageItem||The image item to be matched. This is a required argument.|
|searchValue||The value to be found. This is an optional argument. When this argument is not specified, the current contents of the imageItem is used as the match value.|
|startItem||A number that indicates the item number at which the search is to begin. If this argument is not specified, searching begins at the first item in the Stringlist for FindImageItem, and at the last item for FindImageItemUp|
|operator||A string comparison operator that indicates the required relationship between the match value and the item in the sl Stringlist. Valid comparison operators are |
- FindImageItemUp is available as of Sirius Mods version 7.1.
- FindImageItem and FindImageItemUp are especially useful for Stringlists whose contents map to an image. For example, in the following code fragment
%numis set to the number of the list item that is associated with the product with a code of
image product code is binary len 2 desc is string len 30 end image ... %list = new('PRODUCT') fr products %product:code = code %product:desc = desc %rc = %list:addImage end for ... %product:code = 983 %num = %list:findImageItem(%product:code)
- If a searchValue is specified in addition to the imageItem, processing is performed as if the searchValue were assigned to the imageItem and then the imageItem is restored to its original value upon completion. Any datatype conversions required between the searchValue and the imageItem are performed before the search is performed.
That is, this method invocation
%num = %list:findImageItem(%product:code, 422)
is identical to this:
%temp = %product:code %product:code = 422 %num = %list:findImageItem(%product:code) %product:code = %temp
- For inequality comparisons, the appropriate image-item datatype-specific comparison is performed.
For example, this method invocation would start from the last
%listitem and would match an item with a product code of
-1, or any number greater than or equal to zero, but it would not match one with a product code of
%n = %list:findImageItemUp(%product:code, -2, , 'GE')