VBA - Onkey method?

In Excel VBA, I see there is a method called Onkey. It allows you to have the program jump to a sub-routine anytime a certain key is pressed. In my case, while the user is typing into a combo box, I want to use the ENTER key to tell my program to check to see if what they typed is equal to one of the items on the pull-down list.But, the onkey method doesn't seem to exist in BricsCad's VBA... at least not in the help file. It doesn't seem to be working for me, so I am not sure if I am using the command wrong, or if the command is omitted from BricsCad's VBA.I am uncertain what to expect from BricsCad's VBA. Are the general VBA commands available in all applications that license VBA, or perhaps only a subset?Joe Dunfee

Comments

  • Joe, the 'general' VBA commands that are available in all applications that license VBA, can be consulted using the Object Browser. In the VBA editor, press the F2 key to bring up the Object Browser dialog. At the top left, there are two combo boxes, of which the topmost reads <All libraries>. From this lib combo, select VBA: all classes and members that are listed now, are those offered by VBA COM.Key in 'onkey' in the combo box beside the binoculars icon and press the icon: the search result is empty, so this is a method that is not part of the standard VBA tools, but rather one that is part of the Excel COM lib.Visual Basic offers other ways to trap keyboard input events, unfortunately I don't have time to elaborate on those here, it shouldn't be too hard to find an example on the internet.Kind regards.

  • Thank you. Sorry for the ongoing questtions. I am still struggling to wrap my head around visual basic. Your reply helped clear a lot of things up for me.Joe Dunfee

  • Hi Joe,Why not use ComboBox.MatchRequired = true?In that case, the user can not input items that are not in the list.Otherwise you can use the "onchange" method to check if the input is in the list.Huib.

  • Huib, the reason I am not using ComboBox.MatchRequired = true? is that I do want to allow the user to input any size they want. But, most of the time the sizes on the list is what is used.I am using "onchange" method to initiate another routine which checks to see if the size is on the list. It uses a for-next loop to compare the users value to every item on my list. If it is not on the list, I have some red text "Non Standard" which I change from visible=false to visible=true. This way the user is alterted to the fact.The drawback to "onchange" is that it occurs every time the user types something. Not just when they are finished. I was initially concerned that the subroutine would take too much time to run and not allow the user to type fast enough. But, so far, the time for this comparison has not been a problem.Joe Dunfee

This discussion has been closed.