cancel program within error handler?

cancel program within error handler?

Anonymous
Not applicable
748 Views
8 Replies
Message 1 of 9

cancel program within error handler?

Anonymous
Not applicable
(sorry if there was a duplicate post)

I was wondering if there is a way to get VB to recognize when the ESC key
is hit.

Normally it does, but I have an error handler that repeats a sequence of
code, just in case the user doesn't pick an object with GetEntity.

RETRY:
On Error Resume Next
ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to test
for intersection:"

If Err <> 0 Then
If Err = 13 Then
Err.Clear
ThisDrawing.Utility.Prompt "Invalid Object. "
GoTo RETRY
End If 'Else no object was picked (probably)
Err.Clear
ThisDrawing.Utility.Prompt "No object picked. "
GoTo RETRY
End If

On Error GoTo 0 'Turn off error trapping


Hitting the escape key just causes it to jump back to RETRY.

I figured I could put some code in the error handler that recognizes that
the ESC key is down and end the program from there. Otherwise the only way
to end it is to pick a valid object (if one exists) or hit stop from the VB
IDE.

Any help would be appreciated!

Thanks,
Jason


--
0 Likes
749 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Hi Jason,
Give this a whirl...

J. Foster wrote:

> (sorry if there was a duplicate post)
>
> I was wondering if there is a way to get VB to recognize when the ESC key
> is hit.
>
> Normally it does, but I have an error handler that repeats a sequence of
> code, just in case the user doesn't pick an object with GetEntity.
>
> RETRY:
> On Error Resume Next
> ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to test
> for intersection:"
>
> If Err <> 0 Then
> If Err = 13 Then
> Err.Clear
> ThisDrawing.Utility.Prompt "Invalid Object. "
> GoTo RETRY
> End If 'Else no object was picked (probably)
> Err.Clear
> ThisDrawing.Utility.Prompt "No object picked. "
> GoTo RETRY
> End If
>
> On Error GoTo 0 'Turn off error trapping
>
>
> Hitting the escape key just causes it to jump back to RETRY.
>
> I figured I could put some code in the error handler that recognizes that
> the ESC key is down and end the program from there. Otherwise the only way
> to end it is to pick a valid object (if one exists) or hit stop from the VB
> IDE.
>
> Any help would be appreciated!
>
> Thanks,
> Jason
>
>
> --
>
>
>
>
0 Likes
Message 3 of 9

Anonymous
Not applicable
Jason

Some lines of a code i use
i write this with the help of Frank Oquendo (thank Frank)

If Err Then
'If no object selected
If ThisDrawing.GetVariable("errno") = 7 Then
Err.Clear
MsgBox "Aucun objet sélectionné", , "Application GEomexpert"
GoTo StartLoop
Else
Set Get_bloc = objpicked
End If
'If escape (Acad 2000)
If Err.Number = -2147352567 Then
erreur_interceptee = "ESCAPE"
Err.Clear
End If
Else
......
Bernard
ATC
45700 Villemandeur
France

J. Foster a écrit dans le message :
[email protected]...
> (sorry if there was a duplicate post)
>
> I was wondering if there is a way to get VB to recognize when the ESC key
> is hit.
>
> Normally it does, but I have an error handler that repeats a sequence of
> code, just in case the user doesn't pick an object with GetEntity.
>
> RETRY:
> On Error Resume Next
> ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to
test
> for intersection:"
>
> If Err <> 0 Then
> If Err = 13 Then
> Err.Clear
> ThisDrawing.Utility.Prompt "Invalid Object. "
> GoTo RETRY
> End If 'Else no object was picked (probably)
> Err.Clear
> ThisDrawing.Utility.Prompt "No object picked. "
> GoTo RETRY
> End If
>
> On Error GoTo 0 'Turn off error trapping
>
>
> Hitting the escape key just causes it to jump back to RETRY.
>
> I figured I could put some code in the error handler that recognizes that
> the ESC key is down and end the program from there. Otherwise the only
way
> to end it is to pick a valid object (if one exists) or hit stop from the
VB
> IDE.
>
> Any help would be appreciated!
>
> Thanks,
> Jason
>
>
> --
>
>
>
0 Likes
Message 4 of 9

Anonymous
Not applicable
Thanks!!

--

"Bernard Flavignard" wrote in message
news:[email protected]...
> Jason
>
> Some lines of a code i use
> i write this with the help of Frank Oquendo (thank Frank)
>
> If Err Then
> 'If no object selected
> If ThisDrawing.GetVariable("errno") = 7 Then
> Err.Clear
> MsgBox "Aucun objet sélectionné", , "Application GEomexpert"
> GoTo StartLoop
> Else
> Set Get_bloc = objpicked
> End If
> 'If escape (Acad 2000)
> If Err.Number = -2147352567 Then
> erreur_interceptee = "ESCAPE"
> Err.Clear
> End If
> Else
> ......
> Bernard
> ATC
> 45700 Villemandeur
> France
>
> J. Foster a écrit dans le message :
> [email protected]...
> > (sorry if there was a duplicate post)
> >
> > I was wondering if there is a way to get VB to recognize when the ESC
key
> > is hit.
> >
> > Normally it does, but I have an error handler that repeats a sequence of
> > code, just in case the user doesn't pick an object with GetEntity.
> >
> > RETRY:
> > On Error Resume Next
> > ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to
> test
> > for intersection:"
> >
> > If Err <> 0 Then
> > If Err = 13 Then
> > Err.Clear
> > ThisDrawing.Utility.Prompt "Invalid Object. "
> > GoTo RETRY
> > End If 'Else no object was picked (probably)
> > Err.Clear
> > ThisDrawing.Utility.Prompt "No object picked. "
> > GoTo RETRY
> > End If
> >
> > On Error GoTo 0 'Turn off error trapping
> >
> >
> > Hitting the escape key just causes it to jump back to RETRY.
> >
> > I figured I could put some code in the error handler that recognizes
that
> > the ESC key is down and end the program from there. Otherwise the only
> way
> > to end it is to pick a valid object (if one exists) or hit stop from the
> VB
> > IDE.
> >
> > Any help would be appreciated!
> >
> > Thanks,
> > Jason
> >
> >
> > --
> >
> >
> >
>
>
0 Likes
Message 5 of 9

Anonymous
Not applicable
oops. I spoke too soon. If I hit escape, it works great and I can exit out
of the program. But if I click into empty space, I get the same result as
when I hit escape, when I want to retry the GetSelection. This is
appearantly because clicking into empty space produces the same errornum as
Escape.

Thank you, though.

I'm going to try some of Minkwitz' code, I'll see if that works.

--

"Bernard Flavignard" wrote in message
news:[email protected]...
> Jason
>
> Some lines of a code i use
> i write this with the help of Frank Oquendo (thank Frank)
>
> If Err Then
> 'If no object selected
> If ThisDrawing.GetVariable("errno") = 7 Then
> Err.Clear
> MsgBox "Aucun objet sélectionné", , "Application GEomexpert"
> GoTo StartLoop
> Else
> Set Get_bloc = objpicked
> End If
> 'If escape (Acad 2000)
> If Err.Number = -2147352567 Then
> erreur_interceptee = "ESCAPE"
> Err.Clear
> End If
> Else
> ......
> Bernard
> ATC
> 45700 Villemandeur
> France
>
> J. Foster a écrit dans le message :
> [email protected]...
> > (sorry if there was a duplicate post)
> >
> > I was wondering if there is a way to get VB to recognize when the ESC
key
> > is hit.
> >
> > Normally it does, but I have an error handler that repeats a sequence of
> > code, just in case the user doesn't pick an object with GetEntity.
> >
> > RETRY:
> > On Error Resume Next
> > ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to
> test
> > for intersection:"
> >
> > If Err <> 0 Then
> > If Err = 13 Then
> > Err.Clear
> > ThisDrawing.Utility.Prompt "Invalid Object. "
> > GoTo RETRY
> > End If 'Else no object was picked (probably)
> > Err.Clear
> > ThisDrawing.Utility.Prompt "No object picked. "
> > GoTo RETRY
> > End If
> >
> > On Error GoTo 0 'Turn off error trapping
> >
> >
> > Hitting the escape key just causes it to jump back to RETRY.
> >
> > I figured I could put some code in the error handler that recognizes
that
> > the ESC key is down and end the program from there. Otherwise the only
> way
> > to end it is to pick a valid object (if one exists) or hit stop from the
> VB
> > IDE.
> >
> > Any help would be appreciated!
> >
> > Thanks,
> > Jason
> >
> >
> > --
> >
> >
> >
>
>
0 Likes
Message 6 of 9

Anonymous
Not applicable
I think the "GetAsyncKeyState" looks like what I need, but I don't seem to
have that function. Any idea where I could find it?

--

"Minkwitz Design" wrote in message
news:[email protected]...
> Hi Jason,
> Give this a whirl...
>
> J. Foster wrote:
>
> > (sorry if there was a duplicate post)
> >
> > I was wondering if there is a way to get VB to recognize when the ESC
key
> > is hit.
> >
> > Normally it does, but I have an error handler that repeats a sequence of
> > code, just in case the user doesn't pick an object with GetEntity.
> >
> > RETRY:
> > On Error Resume Next
> > ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to
test
> > for intersection:"
> >
> > If Err <> 0 Then
> > If Err = 13 Then
> > Err.Clear
> > ThisDrawing.Utility.Prompt "Invalid Object. "
> > GoTo RETRY
> > End If 'Else no object was picked (probably)
> > Err.Clear
> > ThisDrawing.Utility.Prompt "No object picked. "
> > GoTo RETRY
> > End If
> >
> > On Error GoTo 0 'Turn off error trapping
> >
> >
> > Hitting the escape key just causes it to jump back to RETRY.
> >
> > I figured I could put some code in the error handler that recognizes
that
> > the ESC key is down and end the program from there. Otherwise the only
way
> > to end it is to pick a valid object (if one exists) or hit stop from the
VB
> > IDE.
> >
> > Any help would be appreciated!
> >
> > Thanks,
> > Jason
> >
> >
> > --
> >
> >
> >
> >
>
>


----------------------------------------------------------------------------
----


> VERSION 1.0 CLASS
> BEGIN
> MultiUse = -1 'True
> END
> Attribute VB_Name = "ThisDrawing"
> Attribute VB_GlobalNameSpace = False
> Attribute VB_Creatable = False
> Attribute VB_PredeclaredId = True
> Attribute VB_Exposed = True
> Option Explicit
> Public NounVerb As Boolean
>
> Public Function GetPoint(Optional Pt As Variant, Optional Prompt As
String) As Variant
> On Error Resume Next
> Do
> GetPoint = ThisDrawing.Utility.GetPoint(Pt, Prompt)
> If Err Then
> If StrComp(Err.Description, "User input is a keyword", 1) = 0
Then
> Err.Clear
> Exit Do
> ElseIf GetAsyncKeyState(&H1B) And &H8000 Then
> Err.Clear
> Exit Do
> End If
> Else
> Exit Do
> End If
> Err.Clear
> Loop
> End Function
>
> 'Private Sub AcadDocument_SelectionChanged()
> ' If ThisDrawing.PickfirstSelectionSet.Count > 0 Then
> ' NounVerb = True
> ' End If
> ' If GetAsyncKeyState(&H10) Then NounVerb = False
> 'End Sub
>
> Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
> NounVerb = False
> End Sub
>
> Public Function GetEntity() As AcadEntity
> Dim Ent As AcadEntity
> Dim Pt As Variant
> 'Set Ent = Nothing
> Do
> On Error Resume Next
> ThisDrawing.Utility.GetEntity Ent, Pt, "Pick an Object :"
> If Err Then
> If ThisDrawing.GetVariable("errno") = "7" Then
> Err.Clear
> Else
> Err.Clear
> Exit Do
> End If
> End If
> If Not Ent Is Nothing Then 'Exit Do 'you could also use if typeof ent
is acadblockreference then exit do
> If TypeOf Ent Is AcadLine Or TypeOf Ent Is AcadCircle Or TypeOf
Ent Is AcadArc Then
> Exit Do
> Else
> MsgBox "The Break2Hidden Command Requires an Arc, Cirlce, or
Line."
> End If
> End If
> Loop
> Set GetEntity = Ent
> End Function
>
0 Likes
Message 7 of 9

Anonymous
Not applicable
Oops. I found it! Thanks, that works great!

--

"J. Foster" wrote in message
news:[email protected]...
> I think the "GetAsyncKeyState" looks like what I need, but I don't seem to
> have that function. Any idea where I could find it?
>
> --
>
> "Minkwitz Design" wrote in message
> news:[email protected]...
> > Hi Jason,
> > Give this a whirl...
> >
> > J. Foster wrote:
> >
> > > (sorry if there was a duplicate post)
> > >
> > > I was wondering if there is a way to get VB to recognize when the ESC
> key
> > > is hit.
> > >
> > > Normally it does, but I have an error handler that repeats a sequence
of
> > > code, just in case the user doesn't pick an object with GetEntity.
> > >
> > > RETRY:
> > > On Error Resume Next
> > > ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to
> test
> > > for intersection:"
> > >
> > > If Err <> 0 Then
> > > If Err = 13 Then
> > > Err.Clear
> > > ThisDrawing.Utility.Prompt "Invalid Object. "
> > > GoTo RETRY
> > > End If 'Else no object was picked (probably)
> > > Err.Clear
> > > ThisDrawing.Utility.Prompt "No object picked. "
> > > GoTo RETRY
> > > End If
> > >
> > > On Error GoTo 0 'Turn off error trapping
> > >
> > >
> > > Hitting the escape key just causes it to jump back to RETRY.
> > >
> > > I figured I could put some code in the error handler that recognizes
> that
> > > the ESC key is down and end the program from there. Otherwise the
only
> way
> > > to end it is to pick a valid object (if one exists) or hit stop from
the
> VB
> > > IDE.
> > >
> > > Any help would be appreciated!
> > >
> > > Thanks,
> > > Jason
> > >
> > >
> > > --
> > >
> > >
> > >
> > >
> >
> >
>
>
> --------------------------------------------------------------------------
--
> ----
>
>
> > VERSION 1.0 CLASS
> > BEGIN
> > MultiUse = -1 'True
> > END
> > Attribute VB_Name = "ThisDrawing"
> > Attribute VB_GlobalNameSpace = False
> > Attribute VB_Creatable = False
> > Attribute VB_PredeclaredId = True
> > Attribute VB_Exposed = True
> > Option Explicit
> > Public NounVerb As Boolean
> >
> > Public Function GetPoint(Optional Pt As Variant, Optional Prompt As
> String) As Variant
> > On Error Resume Next
> > Do
> > GetPoint = ThisDrawing.Utility.GetPoint(Pt, Prompt)
> > If Err Then
> > If StrComp(Err.Description, "User input is a keyword", 1) =
0
> Then
> > Err.Clear
> > Exit Do
> > ElseIf GetAsyncKeyState(&H1B) And &H8000 Then
> > Err.Clear
> > Exit Do
> > End If
> > Else
> > Exit Do
> > End If
> > Err.Clear
> > Loop
> > End Function
> >
> > 'Private Sub AcadDocument_SelectionChanged()
> > ' If ThisDrawing.PickfirstSelectionSet.Count > 0 Then
> > ' NounVerb = True
> > ' End If
> > ' If GetAsyncKeyState(&H10) Then NounVerb = False
> > 'End Sub
> >
> > Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
> > NounVerb = False
> > End Sub
> >
> > Public Function GetEntity() As AcadEntity
> > Dim Ent As AcadEntity
> > Dim Pt As Variant
> > 'Set Ent = Nothing
> > Do
> > On Error Resume Next
> > ThisDrawing.Utility.GetEntity Ent, Pt, "Pick an Object :"
> > If Err Then
> > If ThisDrawing.GetVariable("errno") = "7" Then
> > Err.Clear
> > Else
> > Err.Clear
> > Exit Do
> > End If
> > End If
> > If Not Ent Is Nothing Then 'Exit Do 'you could also use if typeof
ent
> is acadblockreference then exit do
> > If TypeOf Ent Is AcadLine Or TypeOf Ent Is AcadCircle Or TypeOf
> Ent Is AcadArc Then
> > Exit Do
> > Else
> > MsgBox "The Break2Hidden Command Requires an Arc, Cirlce, or
> Line."
> > End If
> > End If
> > Loop
> > Set GetEntity = Ent
> > End Function
> >
>
>
0 Likes
Message 8 of 9

Anonymous
Not applicable
Hi Jason,
Sorry I didn't catch your response yesterday. I failed to include a
declaration not contained in the class I attached. The following line of
code has to go in a standard module:

Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As
Integer

And to clean up the other:

Public Function GetEntity() As AcadEntity
Dim Ent As AcadEntity
Dim Pt As Variant
On Error Resume Next
Do
ThisDrawing.Utility.GetEntity Ent, Pt, "Pick an Object :"
If Err Then
If ThisDrawing.GetVariable("errno") = "7" Then
Err.Clear
Else
Err.Clear
Exit Do
End If
End If
If Not Ent Is Nothing Then
Exit Do
End If
Loop
Set GetEntity = Ent
End Function

Both the code and the declaration can go in the same module. But if I
remember correctly, the declaration can not be in a class. The only
reason I placed the other code in the Thisdrawing module was...
ThisDrawing.GetPoint instead of ThisDrawing.Utility.GetPoint

In a standard module you can simply make a call as GetPoint, ect.
Hope this is helpful.
0 Likes
Message 9 of 9

Anonymous
Not applicable
Try the following.

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Const vbEsc = &H1B

Option Explicit

Sub Example()

Dim objText As AcadEntity
Dim ptPick As Variant

On Error Resume Next
GetTextEntity:
ThisDrawing.Utility.GetEntity objText, ptPick, "Select a text entity: "
If (GetAsyncKeyState(vbKeyEscape) And &H8000) Then Exit Sub
If Err <> 0 Then
If ThisDrawing.GetVariable("errno") = 52 Then
Err.Clear
GoTo GetTextEntity
Else
Exit Sub
End If

End If

On Error GoTo 0

End Sub


"J. Foster" wrote in message
news:[email protected]...
> (sorry if there was a duplicate post)
>
> I was wondering if there is a way to get VB to recognize when the ESC key
> is hit.
>
> Normally it does, but I have an error handler that repeats a sequence of
> code, just in case the user doesn't pick an object with GetEntity.
>
> RETRY:
> On Error Resume Next
> ThisDrawing.Utility.GetEntity Line1, dummyPoint, "Pick the line to test
> for intersection:"
>
> If Err <> 0 Then
> If Err = 13 Then
> Err.Clear
> ThisDrawing.Utility.Prompt "Invalid Object. "
> GoTo RETRY
> End If 'Else no object was picked (probably)
> Err.Clear
> ThisDrawing.Utility.Prompt "No object picked. "
> GoTo RETRY
> End If
>
> On Error GoTo 0 'Turn off error trapping
>
>
> Hitting the escape key just causes it to jump back to RETRY.
>
> I figured I could put some code in the error handler that recognizes that
> the ESC key is down and end the program from there. Otherwise the only way
> to end it is to pick a valid object (if one exists) or hit stop from the VB
> IDE.
>
> Any help would be appreciated!
>
> Thanks,
> Jason
>
>
> --
>
>
>
0 Likes