Resume statement

Resume statement

Anonymous
Not applicable
304 Views
4 Replies
Message 1 of 5

Resume statement

Anonymous
Not applicable
Howdy all,

I have the following code... if the user selects an invalid object, I want a
message box displayed and then allow the user to make a new selection. When
I try to force an error by picking on a non text item, I get my message box
as normal, but I can not dismiss the message box and AutoCAD and VBA hang.
I have gotten it to work by adding the line argument after resume i.e.
Resume 21, but I then get two message boxes from the error before allowing
the user to make a new selection.


Dim objText As AcadText
Dim Ent1 As AcadEntity

On Error GoTo Err_Control:

ThisDrawing.Utility.GetEntity Ent1, PtNothing, "Select text object."
Ent1.Highlight True

If TypeOf Ent1 Is AcadText Then
Set objText = Ent1
Else
GoTo Err_Control
End If

Err_Control:
Select Case Err.Number
Case Else
Err.Clear
MsgBox "The object you selected is not a text object. Please make a
new selection.", vbExclamation, "My Error"
Ent1.Highlight False
Resume
End Select





Anyone have any ideas?

TIA.

--
Rob
0 Likes
305 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Rob,
Try an Exit Sub statement as the line before the error handler. Insures
that program flow does not enter the errorhandler again.

Public Sub pick_acadobject()
Dim myacadobj As AcadObject
On Error GoTo errorhandler
ThisDrawing.Utility.GetEntity myacadobj, pickedpoint, "select an AutoCAD
object..."
'object was picked.. do your thing...
Exit Sub

errorhandler:
MsgBox ("you missed. get some glasses... ")
Err.Clear
Resume
End Sub

Cheers,
Ken Hutson
San Antonio, Texas

"Rob Outman" wrote in message
news:47B69526E413625ABC803DD7EA55E95A@in.WebX.maYIadrTaRb...
> Howdy all,
>
> I have the following code... if the user selects an invalid object, I want
a
> message box displayed and then allow the user to make a new selection.
When
> I try to force an error by picking on a non text item, I get my message
box
> as normal, but I can not dismiss the message box and AutoCAD and VBA hang.
> I have gotten it to work by adding the line argument after resume i.e.
> Resume 21, but I then get two message boxes from the error before allowing
> the user to make a new selection.
>
>
> Dim objText As AcadText
> Dim Ent1 As AcadEntity
>
> On Error GoTo Err_Control:
>
> ThisDrawing.Utility.GetEntity Ent1, PtNothing, "Select text object."
> Ent1.Highlight True
>
> If TypeOf Ent1 Is AcadText Then
> Set objText = Ent1
> Else
> GoTo Err_Control
> End If
>
> Err_Control:
> Select Case Err.Number
> Case Else
> Err.Clear
> MsgBox "The object you selected is not a text object. Please make
a
> new selection.", vbExclamation, "My Error"
> Ent1.Highlight False
> Resume
> End Select
>
>
>
>
>
> Anyone have any ideas?
>
> TIA.
>
> --
> Rob
>
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Ken,

Thanx for the advice... I guess I didn't grab that part of the code when I
was cutting and pasting... I actually do have that in my code. It actually
looks like this at the start of the error handler to avoid entering the
error handler as you mentioned. But unfortunately this does not solve my
Resume problem!

Exit_Here:
Exit Sub
Err_Control:

Thanx,

Rob


"Kenneth Hutson" wrote in message
news:9B585E90BC63A5C77ABF224E9EBCDBF5@in.WebX.maYIadrTaRb...
> Rob,
> Try an Exit Sub statement as the line before the error handler. Insures
> that program flow does not enter the errorhandler again.
>
> Public Sub pick_acadobject()
> Dim myacadobj As AcadObject
> On Error GoTo errorhandler
> ThisDrawing.Utility.GetEntity myacadobj, pickedpoint, "select an
AutoCAD
> object..."
> 'object was picked.. do your thing...
> Exit Sub
>
> errorhandler:
> MsgBox ("you missed. get some glasses... ")
> Err.Clear
> Resume
> End Sub
>
> Cheers,
> Ken Hutson
> San Antonio, Texas
>
> "Rob Outman" wrote in message
> news:47B69526E413625ABC803DD7EA55E95A@in.WebX.maYIadrTaRb...
> > Howdy all,
> >
> > I have the following code... if the user selects an invalid object, I
want
> a
> > message box displayed and then allow the user to make a new selection.
> When
> > I try to force an error by picking on a non text item, I get my message
> box
> > as normal, but I can not dismiss the message box and AutoCAD and VBA
hang.
> > I have gotten it to work by adding the line argument after resume i.e.
> > Resume 21, but I then get two message boxes from the error before
allowing
> > the user to make a new selection.
> >
> >
> > Dim objText As AcadText
> > Dim Ent1 As AcadEntity
> >
> > On Error GoTo Err_Control:
> >
> > ThisDrawing.Utility.GetEntity Ent1, PtNothing, "Select text object."
> > Ent1.Highlight True
> >
> > If TypeOf Ent1 Is AcadText Then
> > Set objText = Ent1
> > Else
> > GoTo Err_Control
> > End If
> >
> > Err_Control:
> > Select Case Err.Number
> > Case Else
> > Err.Clear
> > MsgBox "The object you selected is not a text object. Please
make
> a
> > new selection.", vbExclamation, "My Error"
> > Ent1.Highlight False
> > Resume
> > End Select
> >
> >
> >
> >
> >
> > Anyone have any ideas?
> >
> > TIA.
> >
> > --
> > Rob
> >
> >
>
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Heya Rob,
This seems works fairly well. Remember that the user may not have anything
to select. User may be looking at an empty layout or drawing. Give a choice
to bail out or retry in that case.

Public Sub pick_a_text()
Dim myacadobj As AcadEntity
Dim response As Variant
Dim pickpoint As Variant

On Error Resume Next
ThisDrawing.Utility.GetEntity myacadobj, pickpoint, "Select a text..."
Select Case True
Case Err.Number <> 0
Err.Clear
response = MsgBox("you missed everything", vbRetryCancel)
If response = 4 Then
pick_a_text
Else
Exit Sub
End If
Case Else
If TypeOf myacadobj Is AcadText Then
MsgBox ("good choice")
'do stuff here
Else
response = MsgBox("not text..", vbRetryCancel)
If response = 4 Then
pick_a_text
End If
End If
End Select
End Sub


Cheers,
Kenneth Hutson
San Antonio, Texas

"Rob Outman" wrote in message
news:ABD6C6654C921E79707D19ADA6AC8957@in.WebX.maYIadrTaRb...
> Hi Ken,
>
> Thanx for the advice... I guess I didn't grab that part of the code when I
> was cutting and pasting... I actually do have that in my code. It
actually
> looks like this at the start of the error handler to avoid entering the
> error handler as you mentioned. But unfortunately this does not solve my
> Resume problem!
>
> Exit_Here:
> Exit Sub
> Err_Control:
>
> Thanx,
>
> Rob
>
>
> "Kenneth Hutson" wrote in message
> news:9B585E90BC63A5C77ABF224E9EBCDBF5@in.WebX.maYIadrTaRb...
> > Rob,
> > Try an Exit Sub statement as the line before the error handler. Insures
> > that program flow does not enter the errorhandler again.
> >
> > Public Sub pick_acadobject()
> > Dim myacadobj As AcadObject
> > On Error GoTo errorhandler
> > ThisDrawing.Utility.GetEntity myacadobj, pickedpoint, "select an
> AutoCAD
> > object..."
> > 'object was picked.. do your thing...
> > Exit Sub
> >
> > errorhandler:
> > MsgBox ("you missed. get some glasses... ")
> > Err.Clear
> > Resume
> > End Sub
> >
> > Cheers,
> > Ken Hutson
> > San Antonio, Texas
> >
> > "Rob Outman" wrote in message
> > news:47B69526E413625ABC803DD7EA55E95A@in.WebX.maYIadrTaRb...
> > > Howdy all,
> > >
> > > I have the following code... if the user selects an invalid object, I
> want
> > a
> > > message box displayed and then allow the user to make a new selection.
> > When
> > > I try to force an error by picking on a non text item, I get my
message
> > box
> > > as normal, but I can not dismiss the message box and AutoCAD and VBA
> hang.
> > > I have gotten it to work by adding the line argument after resume i.e.
> > > Resume 21, but I then get two message boxes from the error before
> allowing
> > > the user to make a new selection.
> > >
> > >
> > > Dim objText As AcadText
> > > Dim Ent1 As AcadEntity
> > >
> > > On Error GoTo Err_Control:
> > >
> > > ThisDrawing.Utility.GetEntity Ent1, PtNothing, "Select text
object."
> > > Ent1.Highlight True
> > >
> > > If TypeOf Ent1 Is AcadText Then
> > > Set objText = Ent1
> > > Else
> > > GoTo Err_Control
> > > End If
> > >
> > > Err_Control:
> > > Select Case Err.Number
> > > Case Else
> > > Err.Clear
> > > MsgBox "The object you selected is not a text object. Please
> make
> > a
> > > new selection.", vbExclamation, "My Error"
> > > Ent1.Highlight False
> > > Resume
> > > End Select
> > >
> > >
> > >
> > >
> > >
> > > Anyone have any ideas?
> > >
> > > TIA.
> > >
> > > --
> > > Rob
> > >
> > >
> >
> >
>
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
Thanx Ken,

That worx great!

Rob

"Kenneth Hutson" wrote in message
news:621E7AC4D7656711574352DFA1FB6894@in.WebX.maYIadrTaRb...
> Heya Rob,
> This seems works fairly well. Remember that the user may not have
anything
> to select. User may be looking at an empty layout or drawing. Give a
choice
> to bail out or retry in that case.
>
> Public Sub pick_a_text()
> Dim myacadobj As AcadEntity
> Dim response As Variant
> Dim pickpoint As Variant
>
> On Error Resume Next
> ThisDrawing.Utility.GetEntity myacadobj, pickpoint, "Select a text..."
> Select Case True
> Case Err.Number <> 0
> Err.Clear
> response = MsgBox("you missed everything", vbRetryCancel)
> If response = 4 Then
> pick_a_text
> Else
> Exit Sub
> End If
> Case Else
> If TypeOf myacadobj Is AcadText Then
> MsgBox ("good choice")
> 'do stuff here
> Else
> response = MsgBox("not text..", vbRetryCancel)
> If response = 4 Then
> pick_a_text
> End If
> End If
> End Select
> End Sub
>
>
> Cheers,
> Kenneth Hutson
> San Antonio, Texas
>
> "Rob Outman" wrote in message
> news:ABD6C6654C921E79707D19ADA6AC8957@in.WebX.maYIadrTaRb...
> > Hi Ken,
> >
> > Thanx for the advice... I guess I didn't grab that part of the code when
I
> > was cutting and pasting... I actually do have that in my code. It
> actually
> > looks like this at the start of the error handler to avoid entering the
> > error handler as you mentioned. But unfortunately this does not solve
my
> > Resume problem!
> >
> > Exit_Here:
> > Exit Sub
> > Err_Control:
> >
> > Thanx,
> >
> > Rob
> >
> >
> > "Kenneth Hutson" wrote in message
> > news:9B585E90BC63A5C77ABF224E9EBCDBF5@in.WebX.maYIadrTaRb...
> > > Rob,
> > > Try an Exit Sub statement as the line before the error handler.
Insures
> > > that program flow does not enter the errorhandler again.
> > >
> > > Public Sub pick_acadobject()
> > > Dim myacadobj As AcadObject
> > > On Error GoTo errorhandler
> > > ThisDrawing.Utility.GetEntity myacadobj, pickedpoint, "select an
> > AutoCAD
> > > object..."
> > > 'object was picked.. do your thing...
> > > Exit Sub
> > >
> > > errorhandler:
> > > MsgBox ("you missed. get some glasses... ")
> > > Err.Clear
> > > Resume
> > > End Sub
> > >
> > > Cheers,
> > > Ken Hutson
> > > San Antonio, Texas
> > >
> > > "Rob Outman" wrote in message
> > > news:47B69526E413625ABC803DD7EA55E95A@in.WebX.maYIadrTaRb...
> > > > Howdy all,
> > > >
> > > > I have the following code... if the user selects an invalid object,
I
> > want
> > > a
> > > > message box displayed and then allow the user to make a new
selection.
> > > When
> > > > I try to force an error by picking on a non text item, I get my
> message
> > > box
> > > > as normal, but I can not dismiss the message box and AutoCAD and VBA
> > hang.
> > > > I have gotten it to work by adding the line argument after resume
i.e.
> > > > Resume 21, but I then get two message boxes from the error before
> > allowing
> > > > the user to make a new selection.
> > > >
> > > >
> > > > Dim objText As AcadText
> > > > Dim Ent1 As AcadEntity
> > > >
> > > > On Error GoTo Err_Control:
> > > >
> > > > ThisDrawing.Utility.GetEntity Ent1, PtNothing, "Select text
> object."
> > > > Ent1.Highlight True
> > > >
> > > > If TypeOf Ent1 Is AcadText Then
> > > > Set objText = Ent1
> > > > Else
> > > > GoTo Err_Control
> > > > End If
> > > >
> > > > Err_Control:
> > > > Select Case Err.Number
> > > > Case Else
> > > > Err.Clear
> > > > MsgBox "The object you selected is not a text object. Please
> > make
> > > a
> > > > new selection.", vbExclamation, "My Error"
> > > > Ent1.Highlight False
> > > > Resume
> > > > End Select
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Anyone have any ideas?
> > > >
> > > > TIA.
> > > >
> > > > --
> > > > Rob
> > > >
> > > >
> > >
> > >
> >
> >
>
>
0 Likes