DIAdem Help

Method: InStr for VBS

  • Updated2024-09-12
  • 2 minute(s) read

Method: InStr for VBS

Specifies the position in the text where a character or a character string appears in the text for the first time.

vInStr = Object.InStr(start, string, string2, [compare])
ObjectVBS
Object with this method. You do not need to specify this object.
startVariant
Specifies the start position of the search. If you do not specify start, the search starts with the first character. If you specify compare, you must also specify start. If you do not specify compare, you need not specify start.
stringVariant
Specifies the text you want to search through.
string2Variant
Specifies the character string you want to search for.
[compare]Variant
Specifies the type of comparison. Possible settings are vbBinaryCompare and vbTextCompare. If you do not specify compare, the InStr method performs a binary comparison.
vInStrVariant
Receives the position of a character or a character string in a text. Possible return values:
ConditionReturn value
string is an empty string0
string or string2 is NullNull
string2 is an empty string1
string2 is not in string0
string2 is in stringPosition of string2
start is greater than the length of string0

The following example searches a text in various character strings:

Dim MyPos
MyPos = InStr("abcdabcde", "c")                   'Returns 3
Call MsgBox(MyPos) 
MyPos = InStr("abcdabcde", "C")                   'Returns 0
Call MsgBox(MyPos) 
MyPos = InStr(1, "abcdabcde", "C", vbTextCompare) 'Returns 3
Call MsgBox(MyPos)

See Also

Objects Overview

Related Topics

Filter | InStr | InStrB | InStrRev | Join | LCase | Left | LeftB | Len | LenB | LTrim | Mid | MidB | Replace | Right | RightB | RTrim | Space | Split | StrComp | String | StrReverse | Trim | UCase

Log in to get a better experience