Results 1 to 7 of 7

Thread: Help with Esc key

  1. #1
    Member
    Join Date
    2016-01
    Posts
    33
    Login to Give a bone
    0

    Default Help with Esc key

    Hello everyone

    I use "selectatpoint" in my program with VBA, the problem is there is two expected error from the user 1)first to not press in entity in this case I want to resume the command and ask him again to select an entity 2)the second error when he press Esc key to cancel the command in this case I want to exit sub

    The problem is how to differentiate between these two errors (I tried Err.number but it gives the same number)

    Any advice is really appreciated

    Thank you

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

    Default Re: Help with Esc key

    1. Test the variable you are assigning the picked ent to. Use If..TypeOf to test if they pick the wrong type and Or Null if they don't pick anything.

    2. Search this forum for the windows api GetAsyncKeyState function.
    C:> ED WORKING....


    LinkedIn

  3. #3
    Member
    Join Date
    2016-01
    Posts
    33
    Login to Give a bone
    0

    Default Re: Help with Esc key

    Thank you for you help

    I searched the forum as you said and I found this link
    http://forums.augi.com/showthread.ph...tAsyncKeyState

    and I tried the code but it usually works but not always

    I don't imagine that there is no simple solution for differentiate between pressing Esc key and click on no object when using getentity function

    here the part of the code
    ============================
    SelectionPart:
    On Error GoTo No_Entity
    Utility.GetEntity ob, P1, vbCrLf & "Select object to offset: "

    No_Entity:
    'put code here to differentiate between two cases
    ' if the user misselect the object go back to selection part
    ' if he press ESC key to cancel the command then exit sub
    ===========================

    thank you

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

    Default Re: Help with Esc key

    In that thread you linked to, only the tip I provided will test against [ESC]. The other post does not. It only tests if an obj was selected. To do what you want, you need to treat each condition you want to test for.
    C:> ED WORKING....


    LinkedIn

  5. #5
    Member
    Join Date
    2016-01
    Posts
    33
    Login to Give a bone
    0

    Default Re: Help with Esc key

    Thank you for your help

    but I noticed some thing that will drive me crazy if no one explain it
    Here is the written code
    ====================
    Select Case Err.Number
    Case -2147352567

    If GetAsyncKeyState(VK_LBUTTON) > 0 Then
    Debug.Print "no shape"
    Err.Clear
    Resume SelectionPart
    End If
    Case Else
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "YourProcedureName"
    Resume EndProg
    End Select
    ====================
    The problem is when I run a code and click on no shape the code doesn't detect it but when I put debug break point and ran the code step by step It works great

    What is the problem? does these function need some time to detect? If so how can I cross these dilemma ?

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

    Default Re: Help with Esc key

    You're trying to use one piece of logic to check for everything. It won't work. The GetAsyncKeyState function just checks to see what key was pressed. You're only interested if the user pressed [ESC]. If he did, you clean up anything your method did and exit cleanly, with no error messages. Now, if the user fails to select an object, that's a whole other problem. Deal with it separately. By including "Resume SelectionPart" in your test for [ESC], you don't let your user cancel the function by using the [ESC] key. Use a separate Case condition to test for when no object is selected.
    C:> ED WORKING....


    LinkedIn

  7. #7
    Member
    Join Date
    2016-01
    Posts
    33
    Login to Give a bone
    0

    Default Re: Help with Esc key

    Ok I agree with you completely

    The problem is the following line didn't detect pressing Esc
    If GetAsyncKeyState(VK_ESCAPE) And &H8000 > 0 Then
    can you tell me what is the wrong?

    My analysis is these function gives -32767 when I press Esc key, and 0 in other cases and

    -32767 and &H8000 gives -32768
    which is less than zero

    am I right??

    Thank you

Posting Permissions

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