Srch: Difference between revisions
m (1 revision) |
(No difference)
|
Revision as of 14:11, 15 January 2012
Srch(array-name,argument[,row])
Srch(array-name$,argument$[,row])
The Srch internal function searches an array and returns the row number matching the argument. The argument must be the same data type (string or numeric) as the array. The optional "row" parameter defines the starting array element for the search.
Optional Case Insensitivity and Substring matching
If argument$ begins with ^ then the ^ is stripped and the search becomes case insensitive AND str2$ is regarded as a substring.
For example:
a$(1)='abc' a$(2)='def' srch(mat a$,'^B') returns 1
Comments and Examples
The example below will find the selected item in a combo box
500 combo_choice$=srch(mat array-name$,"^^")
When the search is unsuccessful, Srch returns -1 (unless option 56 is enabled, in which case srch would return a 0). In line 510 below, if STATES$ is a string array containing the 50 valid two-letter state abbreviations, then a data entry program could check whether the operator entered a correct abbreviation into the variable ST$ by the following:
500 LINPUT ST$ 510 If Srch(Mat States$,ST$) = -1 then goto 500
Related Functions
Technical Considerations
- If a match was not found, Srch will return -1.