Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Function Declaration
-
Function InStr(Optional Arg1 As Variant, Optional Arg2 As Variant, Optional Arg3 As Variant, Optional Compare As VbCompareMethod = vbBinaryCompare)
If Arg3 is not present then Arg1 is used as the string to be searched, and Arg2 is used as the pattern (and the start position is 1). If Arg3 IS present then Arg1 is used as a string and Arg2 is used as the pattern.
Parameter |
Description |
---|---|
Arg1 |
Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains the data value Null, an error occurs. This argument is required if Compare is specified. |
Arg2 |
String expression to search. |
Arg3 |
String expression sought. |
Compare |
Specifies the type of string comparison. If compare is the data value Null, an error occurs. If Compare is omitted, the Option Compare setting determines the type of comparison. Specify a valid LCID (LocaleID) to use locale-specific rules in the comparison. |
Runtime Semantics.
§ Returns a Long specifying the position of the first occurrence of one string within another.
§ The Compare argument can have the following values (if omitted, it uses the <option-compare-directive> of the calling module):
Constant |
Value |
Description |
---|---|---|
vbBinaryCompare |
0 |
Performs a binary comparison. |
vbTextCompare |
1 |
Performs a textual comparison. |
§ InStr returns the following values:
If |
|
---|---|
Arg2 is zero-length |
0 |
Arg2 is Null |
Null |
Arg3 is zero-length |
Arg1 |
Arg3 is Null |
Null |
Arg3 is not found |
0 |
Arg3 is found within Arg2 |
Position at which match is found |
Arg1 > Arg3 |
0 |
§ The InStrB function is used with byte data contained in a string. Instead of returning the character position of the first occurrence of one string within another, InStrB returns the byte position.