Add ESC key to ERRor Check vba v02

Discussion in 'AutoCAD' started by Paul Richardson, Jun 23, 2004.

  1. Hi All,
    I would like my code to issue "Select a Wall" until one is selected. The
    way the code stands it keeps prompting if empty space is selected or another
    entity which I want. I would like to be able to ESC by hitting said key.
    right now I have to select an object to exit. I have included my latest
    attempt.

    This is what I have now and would like to add ability to hit ESC to escape
    '*********************************
    Retry:
    Me.Hide
    ThisDrawing.Utility.GetEntity entObj, varPkPt, "Select a Wall" & vbCrLf

    If Err <> 0 Then
    Err.Clear
    GoTo Retry
    Exit Sub
    '*********************************
    I tried to chance to the following to capture the ESC key error which I read
    produces a neg value and the application produces a positive value on error.
    This just closes on all errors including selection emply space,hitting
    enter,ESC,right-click. Could someone please tell me what I'm doing wrong.
    Thank You. Paul

    If Err.Number > 0 Then
    Err.Clear
    GoTo Retry
    ElseIf Err.Number < 0 Then
    Err.Clear
    Exit Sub
     
    Paul Richardson, Jun 23, 2004
    #1
  2. Paul Richardson

    MP Guest

    Option Explicit

    '@~~~~~ General Declarations ~~~~~~~@

    Public Const VK_ESCAPE = &H1B
    Declare Function GetAsyncKeyState Lib "user32" _
    (ByVal vKey As Long) As Integer


    Public Function UserEscaped() As Boolean
    If GetAsyncKeyState(VK_ESCAPE) Then UserEscaped = True
    End Function
     
    MP, Jun 23, 2004
    #2
  3. MT, sorry haven't figured out how to implement in my code. Google hasn't
    helped... Easier to blame google than my own ignorance. Quick explanation
    Please?

    Thank You.
     
    Paul Richardson, Jun 23, 2004
    #3
  4. Paul Richardson

    MP Guest

    The code (which was gleaned from past google posts) uses winapi to detect
    key strokes

    (this is one way to use this)
    In whatever project you want to use this in, add a bas module
    paste supplied code into module
    save as EscapeKey.bas or whatever you want to call it(assuming you will want
    to use this facility in future projects as well)

    a function was defined by the supplied code called "UserEscaped()"
    it returns a boolean value depending on what key was entered

    now in whatever code you want to detect the escape key, you can call this
    function thus:
    Sub TestEscapeKey()

    Dim oEnt As AcadEntity
    Dim vp As Variant

    On Error GoTo errtest
    ThisDrawing.Utility.GetEntity oEnt, vp, vbCrLf & "Pick something or Hit the
    escape key"

    errtest:
    If Err Then
    Err.Clear
    '''what kind of err was it???
    If UserEscaped Then
    ThisDrawing.Utility.Prompt vbCrLf & "Escape key hit"
    MsgBox "Escape key hit"
    Else
    ThisDrawing.Utility.Prompt vbCrLf & "Missed a pick"
    MsgBox "Missed a pick"
    End If

    Else
    ThisDrawing.Utility.Prompt vbCrLf & "Got an Entity: " & oEnt.ObjectName
    MsgBox "Got an Entity: " & oEnt.ObjectName
    End If
    ThisDrawing.Utility.Prompt vbCrLf & "Command:"
    Set oEnt = Nothing

    End Sub
     
    MP, Jun 23, 2004
    #4
  5. Thank you much. Paul
     
    Paul Richardson, Jun 23, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.