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