FindImageItem and FindImageItemUp (Stringlist functions): Difference between revisions
m (syntax digram, tags) |
m (→Syntax) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:Stringlist:FindImageItem | {{Template:Stringlist:FindImageItem and FindImageItemUp subtitle}} | ||
Both these methods locate a <var>Stringlist</var> 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 <var>FindImageItem</var> and <var>FindImageItemUp</var> is the direction of the search: <var>FindImageItem</var> searches from the starting point in ascending item number order, while <var>FindImageItemUp</var> searches in descending item number order. | Both these methods locate a <var>Stringlist</var> 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 <var>FindImageItem</var> and <var>FindImageItemUp</var> is the direction of the search: <var>FindImageItem</var> searches from the starting point in ascending item number order, while <var>FindImageItemUp</var> searches in descending item number order. | ||
Both <var>FindImageItem</var> and <var>FindImageItemUp</var> accept four arguments, and they return the item number of the <var>Stringlist</var> 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. | Both <var>FindImageItem</var> and <var>FindImageItemUp</var> accept four arguments, and they return the item number of the <var>Stringlist</var> 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. | ||
==Syntax== | ==Syntax== | ||
{{Template:Stringlist:FindImageItem syntax}} | {{Template:Stringlist:FindImageItem syntax}} | ||
{{Template:Stringlist:FindImageItemUp syntax}} | {{Template:Stringlist:FindImageItemUp syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%number </th> | <tr><th>%number </th> | ||
<td>A numeric variable that is set to the number of the first item in the <var>Stringlist</var> that matches the search criterion, or it is set to 0 if no <var>Stringlist</var> items matched the search criterion. </td></tr> | <td>A numeric variable that is set to the number of the first item in the <var>Stringlist</var> that matches the search criterion, or it is set to 0 if no <var>Stringlist</var> items matched the search criterion. </td></tr> | ||
<tr><th>sl</th> | <tr><th>sl</th> | ||
<td>A <var>Stringlist</var> object. </td></tr> | <td>A <var>Stringlist</var> object. </td></tr> | ||
<tr><th>imageItem </th> | <tr><th>imageItem </th> | ||
<td>The image item to be matched. This is a required argument.</td></tr> | <td>The image item to be matched. This is a required argument.</td></tr> | ||
<tr><th> | |||
<td>The value to be found. This is an optional argument. When this argument is not specified, the current contents of the | <tr><th>searchValue </th> | ||
<tr><th> | <td>The value to be found. This is an optional argument. When this argument is not specified, the current contents of the <var class="term">imageItem</var> is used as the match value. </td></tr> | ||
<tr><th>startItem </th> | |||
<td>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 <var>Stringlist</var> for <var>FindImageItem</var>, and at the last item for <var>FindImageItemUp</var> </td></tr> | <td>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 <var>Stringlist</var> for <var>FindImageItem</var>, and at the last item for <var>FindImageItemUp</var> </td></tr> | ||
<tr><th>operator </th> | <tr><th>operator </th> | ||
<td>A string comparison operator that indicates the required relationship between the match value and the item in the <var class="term">sl</var> <var>Stringlist</var>. Valid comparison operators are < | <td>A string comparison operator that indicates the required relationship between the match value and the item in the <var class="term">sl</var> <var>Stringlist</var>. Valid comparison operators are <code>'EQ'</code>, <code>'NE'</code>, <code>'LE'</code>, <code>'LT'</code>, <code>'GE'</code>, and <code>'GT'</code>. If this argument is not specified or null, an equality test (<code>'EQ'</code>) is done on all <var>Stringlist</var> items.</td></tr> | ||
</table> | </table> | ||
==Usage Notes== | |||
<ul><li><var>FindImageItemUp</var> is available as of <var class="product">Sirius Mods</var> version 7.1. </ul> | |||
==Examples== | ==Examples== | ||
<var>FindImageItem</var> and <var>FindImageItemUp</var> are especially useful for <var> | <ol><li><var>FindImageItem</var> and <var>FindImageItemUp</var> are especially useful for <var>Stringlists</var> whose contents map to an image. For example, in the following code fragment <code>%num</code> is set to the number of the list item that is associated with the product with a code of <code>983</code>: | ||
< | <p class="code">image product | ||
image product | |||
code is binary len 2 | code is binary len 2 | ||
desc is string len 30 | desc is string len 30 | ||
end image | end image | ||
... | |||
%list = new('PRODUCT') | %list = new('PRODUCT') | ||
fr products | fr products | ||
Line 44: | Line 48: | ||
%rc = %list:addImage | %rc = %list:addImage | ||
end for | end for | ||
... | ... | ||
%product:code = 983 | %product:code = 983 | ||
%num = findImageItem( | %num = %list:findImageItem(%product:code) | ||
</ | </p> | ||
If a | <li>If a <var class="term">searchValue</var> is specified in addition to the <var class="term">imageItem</var>, processing is performed as if the <var class="term">searchValue</var> were assigned to the <var class="term">imageItem</var> and then the <var class="term">imageItem</var> is restored to its original value upon completion. Any datatype conversions required between the <var class="term">searchValue</var> and the <var class="term">imageItem</var> are performed before the search is performed. | ||
That is, this method invocation | That is, this method invocation | ||
< | <p class="code">%num = %list:findImageItem(%product:code, 422) | ||
%num = %list:findImageItem(%product:code, 422) | </p> | ||
</ | |||
is identical to this: | is identical to this: | ||
< | <p class="code">%temp = %product:code | ||
%temp = %product:code | |||
%product:code = 422 | %product:code = 422 | ||
%num = %list:findImageItem(%product:code) | %num = %list:findImageItem(%product:code) | ||
%product:code = %temp | %product:code = %temp | ||
</ | </p> | ||
< | <li>For inequality comparisons, the appropriate image-item datatype-specific comparison is performed. | ||
For example, this method invocation would start from the last <code>%list</code> item and would match an item with a product code of <code>-2</code>, <code>-1</code>, or any number greater than or equal to zero, but it would not match one with a product code of <code>-3</code> or less: | |||
</ | |||
<p class="code">%n = %list:findImageItemUp(%product:code, -2, , 'GE') | |||
</p></ol> | |||
==See also== | |||
{{Template:Stringlist:FindImageItem and FindImageItemUp footer}} |
Latest revision as of 15:27, 31 October 2012
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.
Syntax
%number = sl:FindImageItem( imageItem, [searchValue], [startItem], [operator])
%number = sl:FindImageItemUp( imageItem, [searchValue], [startItem], - [operator])
Syntax terms
%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 'EQ' , 'NE' , 'LE' , 'LT' , 'GE' , and 'GT' . If this argument is not specified or null, an equality test ('EQ' ) is done on all Stringlist items. |
Usage Notes
- FindImageItemUp is available as of Sirius Mods version 7.1.
Examples
- FindImageItem and FindImageItemUp are especially useful for Stringlists whose contents map to an image. For example, in the following code fragment
%num
is set to the number of the list item that is associated with the product with a code of983
: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
%list
item and would match an item with a product code of-2
,-1
, or any number greater than or equal to zero, but it would not match one with a product code of-3
or less:%n = %list:findImageItemUp(%product:code, -2, , 'GE')