Results 1 to 14 of 14
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How clear the input buffer

    Another dumb question, not knowing its name in VBA.
    I have a form where the user can just hold down the Enter key and various sequential procedures run based on the proximate command button that gets focus.
    The problem is, something gets messed up and the procedures don't always run in the order they should.


    I'm guessing it's some problem with the input buffer for keystrokes that craps itself.

    I never had this kind of problem on other computer systems, maybe it's Windows caused or by using an API?
    In any case, I'm looking for a command that will clear the input buffer, so that all the extra keystrokes are discarded before returning control to the form.

    Does VBA have such a thing? Or am I barking up the wrong tree?

    Read the textbox from the bottom up.

    Click image for larger version. 

Name:	240308Buffer1.png 
Views:	24 
Size:	35.6 KB 
ID:	51578

    Click image for larger version. 

Name:	240308Buffer2.png 
Views:	26 
Size:	38.1 KB 
ID:	51579

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @orange #2 The only thing kinda out of the norm are these statements:

    Code:
    Private Declare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongPtr
    ...
    arStrCnt(1, aPos) = GetTickCount64
    These are well documented by IslaDogs, and if there is a problem with them, I'm surprised he hasn't reported it (as far as I've seen).

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    OK you're familiar with the Timing info from Colin. I'm not sure what is causing the sequencing variation. I haven't experienced that.
    I haven't toyed with GetTickCount64.
    I use this api
    Code:
    #If VBA7 Then
    Private Declare PtrSafe Function apiGetTime Lib "winmm.dll" _
                                        Alias "timeGetTime" () As Long
     #Else
    Private Declare Function apiGetTime Lib "winmm.dll" _
                                        Alias "timeGetTime" () As Long
    #End If

  5. #5
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @orange #4 I've got to get permission to post the .accdb. Maybe tomorrow. Then we can see if it's problematic on different machines.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I have never seen issues with GetTickCount64 or GetTickCount but I normally use the latter.

    There is no advantage in using GetTickCount64 for this kind of test. In case it helps, you could try replacing with GetTickCount which will do the same job
    Code:
    Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
    For a discussion about why the two functions exist, see the GetTickCount/GetTickCount64 section of my article: 32 to 64-bit: Conditional Compilation (isladogs.co.uk)

    Or try another timer such as GetSystemTime

    However, I suspect any issues are to do with your code rather than the API used for timing.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ IslaDogs #6 I read your great article, a few times. You mentioned GetTickCount64 pretty extensively, so I went with that.

    I've been testing to see if there's a difference in delays between Sleep 1 and Sleep 15, and it may be my imagination that Sleep 15 runs a bit slower. Is this just my imagination based on the system clock being no finer than 16 ms or has anything changed in Windows or hardware lately?

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I doubt that GetTickCount64 is the issue but I don't use it myself. I do use GetTickCount

    I also only use the Sleep API to cause delays of at least 100 milliseconds and have never tested it for anything less than the system clock interval
    I don't know whether modern PCs have a faster system clock - my main workstation is 12 years old and is still subject to a precision of +-16 milliseconds

    If that isn't precise enough for you, try using the high resolution timer which can measure to <1 microsecond. For most purposes, this is overkill in my opinion.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ All I still haven't heard back from my contact about sharing the db, but I isolated the problem a bit better.
    In the status area of the form (see post #1) there is a procedure that adds text to the textbox.
    At the end of the procedure is a DoEvents. Normally this is there for large status messages that get built for testing, to show immediately.

    It seems that holding down the Enter key and with the DoEvents running allows the command buttons to run out of order.
    Commenting out the 'DoEvents allows the command buttons (and procedures) to run in proper order.

    I haven't fully wrapped my brain around it yet. I'm guessing it's something like the input buffer is filled with Enters while a procedure is running,
    and then the DoEvents skips what's waiting and goes to the next key press.

    If not for this problem, I would still like to know a way to clear an input buffer if possible.
    Let's say an impatient user starts clicking/typing all over a form while a long procedure is running,
    I want to delete all the clicks and keystrokes to start fresh for the next input.
    Make sense?

  10. #10
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Okay, nothing about clearing user actions from the peanut gallery.

    How about a way to stop all user actions while still allowing DoEvents to run?
    (I think this is not a great solution in some cases, like if the user might need to press a cancel button during a big process.)

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Just thought I would ask Google as that is always my first point of call.
    https://www.mrexcel.com/board/thread...buffer.254206/
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    perhaps lock keyboard and mouse so the buffer doesn't fill in the first place
    https://www.mrexcel.com/board/thread...yboard.410739/

  13. #13
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ Welshgasman & CJ_London #11 & #12
    Thanks for those links. I do search Google first, but I'm often at a disadvantage because I'm not sure what vernacular to use or the name of some MS feature, as MS often changes it from a name that served in other systems for decades. In this case it seems to be an API that might affect all of Windows, and not just Access. Hmmm, not so sure about that.

    Some of the samples look a bit complicated, so I'll have to get into them next chance I get.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by twgonder View Post
    @ Welshgasman & CJ_London #11 & #12
    Thanks for those links. I do search Google first, but I'm often at a disadvantage because I'm not sure what vernacular to use or the name of some MS feature, as MS often changes it from a name that served in other systems for decades. In this case it seems to be an API that might affect all of Windows, and not just Access. Hmmm, not so sure about that.

    Some of the samples look a bit complicated, so I'll have to get into them next chance I get.
    My search was 'clear input buffer vba'
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 01-04-2023, 05:02 PM
  2. Replies: 1
    Last Post: 07-13-2021, 11:42 PM
  3. Clearing Keyboard Buffer in Access VBA
    By sjlevine34 in forum Programming
    Replies: 18
    Last Post: 09-28-2020, 02:22 PM
  4. Clear textbox after input message pops up.
    By newbieX in forum Programming
    Replies: 6
    Last Post: 01-11-2017, 12:33 PM
  5. Replies: 1
    Last Post: 11-04-2014, 12:07 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
  •  
Other Forums: Microsoft Office Forums