Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error Resume Next problem 1

Status
Not open for further replies.

aesseal

Programmer
Nov 29, 2002
23
US
I have a problem with 'on error resume next', or indeed any other error handling routine. The problem is an error is thrown rather than the code entering the handler.

The Code is here:

Public Function printFile(fileToOpen As String, printerName As String) As Boolean

On Error GoTo handler

Dim sEdgeApp As SolidEdgeFramework.Application
Dim sEdgeDft As SolidEdgeDraft.DraftDocument

Set sEdgeApp = CreateObject("SolidEdge.Application")

sEdgeApp.DisplayAlerts = False

sEdgeApp.Documents.Open fileToOpen

Set sEdgeDft = sEdgeApp.Documents(1)

sEdgeDft.PrintOut printerName, 1, vbPRORLandscape, , , , , igPrintAll

sEdgeDft.Close False
sEdgeApp.Quit

Set sEdgeDft = Nothing
Set sEdgeApp = Nothing

printFile = True

Exit Function

handler:

printFile = False

On Error Resume Next

If Not sEdgeDft Is Nothing Then
sEdgeDft.Close False
End If

If Not sEdgeApp Is Nothing Then
sEdgeApp.Quit
End If

Set sEdgeDft = Nothing
Set sEdgeApp = Nothing

End Function

The error occurs on the sEdgeApp.Quit line, and it doesen't resume next. This is a problem as it will be running as a server manager so it can't throw any errors. If I don't try and clean up after an error the server will eventually run out of memory.

Has anybody got any ideas??

Thanks,

Dan
 
I dont think you can nest on error routines. You will have to take out the On Error Resume Next from Handler.
 
I.E. You cant have an error handler within an error handler. At least I think I am right.
 
You were right! I've been doing that for years as well!

FYI I've changed it to:

Public Function printFile(fileToOpen As String, printerName As String) As Boolean


On Error GoTo handler

printFile = True

Dim sEdgeApp As SolidEdgeFramework.Application
Dim sEdgeDft As SolidEdgeDraft.DraftDocument

Set sEdgeApp = CreateObject("SolidEdge.Application")

sEdgeApp.DisplayAlerts = False

sEdgeApp.Documents.Open fileToOpen

Set sEdgeDft = sEdgeApp.Documents(1)

sEdgeDft.PrintOut printerName, 1, vbPRORLandscape, , , , , igPrintAll

If Not sEdgeDft Is Nothing Then
sEdgeDft.Close False
End If

If Not sEdgeApp Is Nothing Then
sEdgeApp.Quit
End If

Set sEdgeDft = Nothing
Set sEdgeApp = Nothing

Exit Function


handler:

printFile = False

Resume Next


End Function




Thanks,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top