Link to home
Start Free TrialLog in
Avatar of Cbel
Cbel

asked on

Using the Instr Function

I am looping through an array called strLines to find strDelete.  If strDelete is not there, i am writing strLines(i) to a text file.

However, if strDelete is contained within strLines(i) - i want to replace strDelete with "" & then write the line.

The code i have is as follows:

For i = LBound(strLines) To UBound(strLines)
    If strLines(i) <> strDelete Then
        Write #1, strLines(i)
    End If
   
    pos = InStr(0, strLines(i), strDelete, vbTextCompare)
    If pos = 0 Then  //not in strLines(i)
         Write #1, strLines(i)
    Else
         strLines(i) = Replace(strLines(i), strDelete, "")
         Write #1, strLines(i)
    End If
Next
Close #1


The error I'm receiving is runtime error 5: Invalid procedure call or argument on line:  pos = ......


Any suggestions please?
ASKER CERTIFIED SOLUTION
Avatar of fluglash
fluglash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fluglash
fluglash

as default its compare option is vbTextCompare
Avatar of Cbel

ASKER

Cheers, that worked.