InStr Function

Category: GUI » Visual Basic 6 » Function

Description: Returns the position of the first occurrence of one string within another Syntax: InStr([start,]string1,string2[,compare])

ParametersDescription
start Optional. Default 1 Numeric expression that sets the starting position for each search
string1 Required. String expression being searched
string2 Required. String expression searched for.
compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings

Compare Argument:

ConstantsValueDescription
vbUseCompareOption -1 Performs a comparison using the setting of the Option Compare statement
vbBinaryCompare 0 Default. Perform a binary comparison
vbTextCompare 1 Perform a textual comparison
vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database

Return Data Type: Long Usage / Example Code: Dim SearchStr as String, SearchChar as String SearchStr = "Banyan Seed"

StatementResult / ValueRemark / Note
instr(SearchStr,"b") 0  
instr(SearchStr,"B") 1  
instr(1,SearchStr,"b",vbTextCompare) 1 is equal to instr(1,SearchStr,"b",vbTextCompare)
instr(SearchStr,"b",vbTextCompare) Error Run-time error '13': Type mismatch
instr(SearchStr,"e") 9  
instr(10,SearchStr,"e") 10 Second occurance
instr("", "e") 0  
instr(4, SearchStr, "") 4 value of start argument
instr(Null, "e") Null  
instr(SearchStr,Null) Null  
xxx xxx  
xxx xxx  

Related Articles:

Tags: String Functions, vb6