Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error handler can't handle mystery error

Posted on 1999-07-15
2
Medium Priority
?
182 Views
Last Modified: 2010-04-30
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?
0
Comment
Question by:ddevon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
jcastr earned 60 total points
ID: 1525138
Before

Trap:
MsgBox "Replace error" & Str(Err.Number) & ": " & Err.Description, , "Error"

you have to put a resume section

Finished:
         Exit Function

Trap:
         MsgBox "Replace error" & Str(Err.Number) & ": " & Err.Description, , "Error"
         Resume Finished


*****************

Error 0 is 'No error encountered' and the call of Err.Number and Err.Description generates an error because there is no one, and also there isn't a RESUME statement in your error handler.



0
 

Author Comment

by:ddevon
ID: 1525139
Thanks, it works fine.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question