Results 1 to 4 of 4

Thread: "ESC" Key press (Exit gracefully)

  1. #1
    Active Member spencer.67965's Avatar
    Join Date
    2004-05
    Posts
    76
    Login to Give a bone
    0

    Default "ESC" Key press (Exit gracefully)

    Hello all,

    Just a quick question. Can anyone tell me how (or show me an example of how) I can exit gracefully out of a VBA program when the user presses the ESC key. When using the command line for user input.

    Thanks,

    Spencer
    ___________________
    AutoCAD 2005 - Win 2k
    Last edited by spencer.67965; 2004-08-26 at 01:47 PM.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,409
    Login to Give a bone
    0

    Default Re: "ESC" Key press (Exit gracefully)

    Put the following in your Declarations section.
    Code:
    'GetAsyncKeyState constants
    Private Enum enGetAsyncKeyState
        VK_ESCAPE = &H1B
        VK_LBUTTON = &H1
        VK_RBUTTON = &H2
        VK_RETURN = &HD
        VK_SPACE = &H20
    End Enum
    
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As enGetAsyncKeyState) As Integer
    Then add the following error handler to your procedure:

    Code:
    Exit_Here:
        ThisDrawing.EndUndoMark
        Exit Sub
         
    Err_Control:
        Select Case Err.Number
        Case -2147352567
            If GetAsyncKeyState(VK_ESCAPE) And &H8000 > 0 Then
                Err.Clear
                Resume Exit_Here
            ElseIf GetAsyncKeyState(VK_LBUTTON) > 0 Then
                Err.Clear
                Resume
            End If
        Case Else
            MsgBox Err.Number & " - " & Err.Description, vbCritical, "YourProcedureName"
            Resume Exit_Here
        End Select
    End Sub
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2002-02
    Location
    Saskatoon, SK Canada
    Posts
    23
    Login to Give a bone
    0

    Default Re: "ESC" Key press (Exit gracefully)

    Hello Spencer.
    Something like this should do the trick:
    Code:
    Sub test()
    
      Dim dblDist As Double
      
      On Error GoTo ErrorHandler
        
        Do
          
          dblDist = ThisDrawing.Utility.GetDistance(, "Enter Distance: ")
          
        Loop While Not IsEmpty(dblDist)
        
    
    ErrorHandler:
      If Err.Number = -2147352567 Then
        Exit Sub
      End If
    
    End Sub
    Hope this helps

    Warren M


    Quote Originally Posted by spencer.67965
    Hello all,

    Just a quick question. Can anyone tell me how (or show me an example of how) I can exit gracefully out of a VBA program when the user presses the ESC key. When using the command line for user input.

    Thanks,

    Spencer
    ___________________
    AutoCAD 2005 - Win 2k

  4. #4
    Active Member spencer.67965's Avatar
    Join Date
    2004-05
    Posts
    76
    Login to Give a bone
    0

    Default Re: "ESC" Key press (Exit gracefully)

    Thanks for the input.


    Spencer

Similar Threads

  1. Replies: 0
    Last Post: 2012-06-06, 11:54 AM
  2. ENTIDADES EN ALIGNMENT COMO "FIXED", "FLOTING" y "FREE"
    By cadia in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2009-02-01, 04:21 AM
  3. Toolbars & "Press & Drag" box
    By gwnelson in forum Revit Architecture - General
    Replies: 5
    Last Post: 2007-04-18, 11:55 AM
  4. Replies: 1
    Last Post: 2006-06-13, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •