$ListLoc: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
<span class="pageSubtitle"><section begin="desc" />Locate string in $list<section end="desc" /></span> | <span class="pageSubtitle"><section begin="desc" />Locate string in $list<section end="desc" /></span> | ||
<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for <var>$ListLoc</var> is [[Locate and LocateUp (Stringlist functions)|Locate]].</p> | <p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for <var>$ListLoc</var> is [[Locate and LocateUp (Stringlist functions)|Locate]] (although, as noted [[#Different order of Locate arguments|below]], the order of the search string and start item arguments has changed).</p> | ||
This function locates a specified string in a $list. | This function locates a specified string in a $list. | ||
Line 76: | Line 76: | ||
</p> | </p> | ||
Note that this use of an image item name simply sets the range of columns for a match. If an entry with an exact match for the image item is required, [[$ListFindI]] should be used.<p> | Note that this use of an image item name simply sets the range of columns for a match. If an entry with an exact match for the image item is required, [[$ListFindI]] should be used. | ||
==Different order of Locate arguments== | |||
As metioned above, the OO equivalent for <var>$ListLoc</var> is <var>[[Locate and LocateUp (Stringlist functions)|Locate]]</var>. However, the order of the search string and start item arguments for <var>Locate</var> and <var>$ListLoc</var> is reversed. The following two lines of code are equivalent, assuming that the $list represented by <code>%list</code> and the <var>Stringlist</var> <code>%strLis</code> are equivalent: | |||
<p class="code">%it = $listLoc(%list, %startNum, 'find this string') | |||
%it = %strLis:locate('find this string', %startNum) | |||
</p> | |||
<ul class="smallAndTightList"> | <ul class="smallAndTightList"> |
Revision as of 13:52, 15 July 2011
<section begin="desc" />Locate string in $list<section end="desc" />
Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for $ListLoc is Locate (although, as noted below, the order of the search string and start item arguments has changed).
This function locates a specified string in a $list.
The $ListLoc function accepts six arguments and returns the item number of the $list item containing the string or an error code.
The first argument is the identifier of the $list in which a string is to be located. This is a required argument.
The second argument is 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 $list.
The third argument is the string to be located. If this argument is not specified, all $list items are considered to contain the search string.
The fourth argument is either a number that specifies the starting column of a range of columns in which the search string must be located or a string containing the name of an image item in the image associated with the $list using $ListImg. In the latter case, the start column for the search is the position of the image item in the image. This is an optional argument and defaults to 1.
The fifth argument is a number that specifies the ending column of a range of columns in which the search string must be located. This is an optional argument and defaults to one of the following values:
- if the fourth argument specifies an image item name, the position of the end of the image item in the image
- otherwise, 6124 for Sirius Mods Version 6.2 and later, and 4096 before.
If the sixth argument is a non-zero integer, then the width of the column range is reduced to a maximum of 256.
The sixth argument is an indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use $list item data translated to uppercase (hence your search string should be passed as an uppercase value). This is an optional argument and defaults to zero. If the sixth argument is 1, then the width of the column range is reduced to a maximum of 256.
Syntax
<section begin="syntax" /> %RESULT = $ListLoc(list_identifier, start, search_string - start_col, end_col, case_ignore) <section end="syntax" />
-5 - Required argument not specified -6 - $List identifier invalid -7 - Item number not found in $list -8 - String not found (if $list empty, -7) -9 - Invalid column range
The following code locates a string in columns 31 through 39 of a $list.
%NUM = $ListLoc(%LIST, , 'EUDAEMONIC', 31, 39)
In the following code, an image is associated with the $list, items are added to the $list from the image and then the $list is searched for an item that contains a particular value in the columns associated with a specific image item.
IMAGE CUST LNAME IS STRING LEN 30 FNAME IS STRING LEN 30 ID IS STRING LEN 9 END IMAGE PREPARE IMAGE CUST %LIST = $ListNew %RC = $ListImg(%LIST, %CUST:LAME) . . . . . FOR EACH RECORD IN LCUST . . . . . %RC = $ListAddI(%LIST) . . . . . END FOR . . . . . %ITEMNUM = $ListLoc(%LIST, , %LOCID, 'ID')
Note that this use of an image item name simply sets the range of columns for a match. If an entry with an exact match for the image item is required, $ListFindI should be used.
Different order of Locate arguments
As metioned above, the OO equivalent for $ListLoc is Locate. However, the order of the search string and start item arguments for Locate and $ListLoc is reversed. The following two lines of code are equivalent, assuming that the $list represented by %list
and the Stringlist %strLis
are equivalent:
%it = $listLoc(%list, %startNum, 'find this string') %it = %strLis:locate('find this string', %startNum)