mark 发表于 2005-8-25 20:07:38

Question 18 answers go here

Kerry 发表于 2005-8-25 20:14:33

... to allow the programmer to employ poor coding habits.
Just kidding, sometime that's a perfectly valid route to go.
:)

Kerry 发表于 2005-8-25 20:33:43

I thought it was to repair the damage done from having to type the word Dim a coupla hundred times a day.
I'll probably get dropped under a camel for that ..

Keith™ 发表于 2005-8-25 20:39:08


Dim filehandle As Integer, _
    nullheader As String * 7, _
    stream   As String, _
    rawRecordAs RawRecordType, _
    i          As Long

Keith™ 发表于 2005-8-25 20:48:59


http://www.theswamp.org/screens/kerry/Michaels%20ScoreCard.png

JohnK 发表于 2005-8-25 21:24:18


http://www.theswamp.org/screens/mp/humilitymodule.png

Kerry 发表于 2005-8-25 21:53:00


In most cases that is indeed the reason ...
However ... it can actually be a very handy tool if used properly ...
Consider a loop that does series of tasks (or even a single task) on a group of objects. We are all familiar with the "For Next" loops ...or at least most of us are ...
It is my understanding (and I am frequently wrong) that this error handler allows you to skip over the items causing this error within the loop ...
example

CharCode = 32
On Error Resume Next
For X = -127 to 127
MsgBox CharCode / X
Next X

Now while the point of this exercise might be pointless, it will catch the divide by zero error that will be generated when X = 0, thus the loop will continue to execute until it is finished.
Now for an example of how it can be used for the lazy programmer ...

Set ThisSSet = ThisDrawing.SelectionSets.Add("NewSSet")
ThisSSet.SelectOnScreen
On Error Resume Next
For Each ACBlock in ThisSSet
MsgBox ACBlock.Name & vbCr & _
            "X:" & ACBlock.XScaleFactor & vbCr & _
            "Y:" & ACBlock.YScaleFactor & vbCr & _
            "Z:" & ACBlock.ZScaleFactor
Next ACBlock

Now what happens is if there is an object that is not a block it will generate an error because of the properties being read and the error handler will do it's job. This is an example of lazy programming as the user could have programmed in a filter to allow for only the selection of blocks. Plus what happens when the function encounters a block that has had the name stripped from the drawing database as in some of the older CadLock drawings.
BUT
If you call another subroutine without an error handler AFTER you use the Resume Next handler, if the called function has an error it will be a pain in the butt to find it because the function will work as though nothing is wrong ... been there done that ... learned the hard way

Keith™ 发表于 2005-8-26 05:08:23

Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues... Sample:Public Function MeSelectionSet(SetNme As String) As AcadSelectionSet
On Error Resume Next

With ThisDrawing.SelectionSets
    Set MeSelectionSet = .Add(SetNme)
    If Err.Number0 Then
      Err.Clear
      .Item(SetNme).Delete
      Set MeSelectionSet = .Add(SetNme)
    End If
End With

End Function

Kerry 发表于 2005-8-26 10:51:29

on error resume next is error avoidance not error handling...
try
catch ex as exception
finally 'optional
end try
is error handling.

Keith™ 发表于 2005-8-26 11:14:56

My guess C++...
页: [1] 2
查看完整版本: Question 18 answers go here