Link to home
Start Free TrialLog in
Avatar of ddevon
ddevon

asked on

Error handler can't handle mystery error

I have a search-and-replace function that worked fine until
it broke. I added an error handler so now it looks like:

Function Replace(txtMain As String, txtSearch As String, txtReplace As String)
 
On Error GoTo Trap
    Dim FoundAt As Integer
    Dim txtWork As String
    txtWork = txtMain

        Do
            FoundAt = InStr(FoundAt + 1, txtWork, txtSearch)
            txtWork = Left$(txtWork, FoundAt - 1) & txtReplace & Mid$(txtWork, FoundAt + Len(txtSearch))
            Loop While (InStr(FoundAt + 1, txtWork, txtSearch) <> 0)
    Replace = txtWork
   
Trap:
MsgBox "Replace error" & Str(Err.Number) & ": " & Err.Description, , "Error"
     
End Function

The message this generates is:
"Replace error 0:"

What is error #0 and why does it have no description?
ASKER CERTIFIED SOLUTION
Avatar of jcastr
jcastr

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 ddevon
ddevon

ASKER

Thanks, it works fine.