-
error code bypass?
Hello
I'm new to this forum. I've been working a bit with writing routines in VB. I use AutoCAD Map 5. I am by no means an expert. Far from it.
I've run into a problem that I hope someone can answer for me.
During some of the batch routines that I have which perform specific tasks, I sometimes get an error on certain maps. This error causes the macro to stop and pops up a dialog box which prompts me to hit the "OK" button. I would like to bypass this error if possible so that the macro will continue to run without waiting for me to hit the "OK" button. (To track down and fix the error on hundreds of maps would be too time consuming)
I have been told that the error is likely an internal MAP error so I was hoping that someone here could help me.
Is there a way that I can place code in my macro that would allow me to bypass this error? (The error is consistant. It is always ERRCODE; Value: 786434.)
Something along these lines:
If err.Number=786434 then
Msgbox "Error occured with internal MAP error number: " & err.Number
else
<do your things here>
end if
Can anyone help me with this?
I appreciate your help.
Mike
-
Re: error code bypass?
Here is my standard error handling. Don't assume though, that is just a Map error. Its more likely that you haven't accounted for all the situations your code is running into. By adding this code to each of your procedures, you will be able to track down those kinds of errors. Note that the flow control is designed so that if an error is generated in this procedure, the msg tells you the context of the error, i.e. the procedure name. The first time you run this, you may get an error that you can fix with your code. Uncomment the Case Is statement and change it to handle this newly identified error and change the main procedure to prevent such errors. You may run into other errors as you develop your application. When you do, just add another Case Is statement.
Code:
Public Sub ErrorTest()
On Error GoTo Err_Control
'Main process
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "ErrorTest"
Err.Clear
Resume Exit_Here
End Select
End Sub
PS, Search the ATP archives for my vba class where I address error handling.
-
1 Attachment(s)
Re: error code bypass?
Thank you for the reply. Of course when it comes to me - I rarely get things correct the first time. I have read your reply - and understand it for the most part - but I'm not quite getting it to work for me. Can you tell me from the code below what I have done wrong? The macro still runs - but the error dialog box (for Error code 786434) still pops up. Have I placed the error handling incorrectly:
Code:
Dim OutputFolder As String
Dim Inputfolder As String
'*************************************************************************************************************
Sub CreateGrayBackgroundDrawing()
Inputfolder = BrowseForFolderF("Select Input folder")
OutputFolder = BrowseForFolderF("Select Output folder")
XRefFolder Inputfolder
MsgBox ("Complete")
End Sub
'*************************************************************************************************************'
Private Function BrowseForFolderF(ByVal msg As String) As String
Dim oBrowser, folderObj, folderAcpt As Object
Dim folderStr As String
Set oBrowser = ThisDrawing.Application.GetInterfaceObject("Shell.Application")
Set folderAcpt = oBrowser.BrowseForFolder(vbOKOnly, msg, vbDefaultButton3, 0)
With folderAcpt
Set folderObj = .Self
folderStr = folderObj.Path
End With
Set folderObj = Nothing
Set folderAcpt = Nothing
Set oBrowser = Nothing
BrowseForFolderF = folderStr
End Function
'*************************************************************************************************************'
Private Function XRefFolder(dirpath As String)
Dim objFolder
Dim objFile
Dim varFs() As Variant
Dim m_objFSO, n, m_lngFileCount
Set m_objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = m_objFSO.GetFolder(dirpath)
Dim Gumby As String
Dim Pokey As Variant
Gumby = "The drawing for area_"
Pokey = objFolder.Name
For Each objFile In objFolder.Files
On Error GoTo Err_Control
tmpFile = objFile.Name
If LCase(Right(tmpFile, 4)) = ".dwg" Then
Dim xrfilename As String
xrfilename = dirpath & "\" & tmpFile
Dim blkname As String
blkname = tmpFile
Dim InsertPoint(0 To 2) As Double
Dim insertedBlock As AcadExternalReference
Dim tempBlock As AcadBlock
InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(xrfilename, blkname, InsertPoint, 1, 1, 1, 0, False)
Set tmpFile = Nothing
End If
Next objFile
Set objFolder = Nothing
Set objFile = Nothing
CheckFolder = varFs
outfile = OutputFolder & "\" & Gumby & Pokey
ThisDrawing.SaveAs outfile
Exit_Here:
Exit Function
Err_Control:
Select Case Err.Number
'Add your Case selections here
Case Is = 786434
'Handle Error
Err.Clear
Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "ErrorTest"
Err.Clear
Resume Exit_Here
End Select
End Function
(I have also included a jpg of the error message that I receive)
-
Re: error code bypass?
That is definitely a Map error. I couldn't find any info in adesk's kb on it and I don't see anything in your function that would generate an adequery. What I would do next is set a breakpoint at the beginning of your function and step through the code until you find the exact line that causes the error.
As far as the error handler goes, it would only work for unhandled errors. Map is handling the error and pops the dialog, so the only thing you can do is correct what is causing the error. It might be something in the drawing or the program's installation. The class names are stored in the registry at hkey_classes.
-
Re: error code bypass?
OK - that makes a lot of sense. That's the information that I was looking for. The drawings in which I am finding the errors are somewhat numerous so I was looking for a way to bypass the error as opposed to fixing the individual issues. It seems that there is some sort of hidden residue left in the drawings that cannot be purged out and won't go away when removing the filters or WBLOCKing the drawing etc. Basically those particuar drawings will simply need to be recreated from scratch.
Thank you very much for the help and the information. I appreciate it.
Mike
-
Re: error code bypass?
Have you tried auditing the dwg?
-
Re: error code bypass?
mmmmm, I'm not exactly sure which routine you are referring to. I have run Recover as well as routines that purge everything and delete all the layer filters etc. Is there another audit routine that I'm unaware of?
-
Re: error code bypass?
The AUDIT command is listed right next to RECOVER under File>Drawing Utilities.