473,388 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Beep wont turn off

1
I have following code

I have text box that takes an input

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEng_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3.     If KeyCode = 13 Then
  4.         KeyAscii = 0
  5.         lblEl.Caption = SPI(txtEng.Text)
  6.     End If
  7. End Sub
After user has entered text it beeps
Mar 1 '07 #1
8 3896
willakawill
1,646 1GB
Which line of the code causes the beep?
Mar 4 '07 #2
Killer42
8,435 Expert 8TB
Which line of the code causes the beep?
Actually, I think a non-multiline textbox always beeps when you press Enter. It can be a real pain.

One way I have avoided it in the past is to hide a command button somewhere off-screen with Default = True so that it captures the Enter, and process it there. There are probably better ways, though. And, of course, the button doesn't necessarily have to be out of sight.
Mar 4 '07 #3
kscmjo
13
You cannot change the keyascii in keydown event.
Use the KeyPress event instead

ie
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text_keypress(keyascii as integer)
  2.    if keyascii=13 then
  3.          keyascii=0
  4. End Sub
Mar 6 '07 #4
kscmjo
13
If you have multiple text boxes on the form it is far easier to use the form Key Press event. You can still use the keydown to look for Enter to process stuff although it is better to process in the lost focus event (in case they don't press enter)

You must set the form Key Preview property to true.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 13 Then
  3.         KeyAscii = 0
  4.     End If
  5. End Sub
  6.  
  7. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  8. 'VB will process the Key down first then the key press
  9. If KeyCode = 13 Then
  10.     ' Process Stuff here
  11.     Text2.SetFocus 'This sets the focus to the next control
  12. End If
  13. End Sub
  14.  
  15. Private Sub Text1_LostFocus()
  16.     'Or it is better to process stuff here in case they do not use Enter
  17.     'Still use the keydown to set the focus to the next control
  18. End Sub
Mar 6 '07 #5
The advantage of Keypress is that it captures the Shift as well as the KeyCode. For example, I am trying to add a bunch of shortcut fields which will enable the user to hop around the window using Alt-x combinations instead of clicking with the mouse. The following code is an example:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Keydown(KeyCode As Integer, Shift As Integer)
  2. '  Shortcut keys added March, 2007 for RSI remediation.
  3.  
  4.    On Error Resume Next
  5.    If Shift = 4 Then  ' Alt Key is being held down
  6.       Select Case KeyCode
  7.          Case vbKeyA
  8.             fldALLPRice.SetFocus
  9.          Case vbKeyD
  10.             fldDTWPrice.SetFocus
  11.          Case vbKeyJ
  12.             fldBJPrice.SetFocus
  13.          Case vbKeyT
  14.             fldTimeEffective.SetFocus
  15.       End Select
  16.    End If
  17.  
  18. End Sub
This works perfectly except that it beeps every time control is returned to the window. I couldn't get the above to work using form_keypress because keypress doesn't capture keys pressed while the Alt key is held down. So I have a dilemma: Keypress will let me reset KeyAscii to zero to avoid the beep, but it can't detect the Alt-key combinations. Keydown detects the Alt-key, but it won't let me reset the KeyCode to zero in order to avoid the infernal beep! Is there a way I can do both--detect the Alt key and turn off the beep? Thanks!
Mar 21 '07 #6
Killer42
8,435 Expert 8TB
I think the code that kscmjo posted does handle both.

By the way, are you sure that you need to do the "hotkey" stuff yourself? What about using the built-in facility. Just set a hot ket on the label before a field, make sure the tabindex values are right, and it should happen automagically.
Mar 21 '07 #7
Killer42, thanks for the great advice. I forgot that I could set hotkeys on the label and through proper setting of the tab order have the hotkey send the user to the textbox. It works perfectly! You saved me a ton of programming throughout the system.

KSCMJO's solution looked like exactly what I wanted, but I couldn't get it to work. That's why I posted my question. Basically, when I held the Alt key down, the keypress event would never fire. So I only got the keydown part to work. But I don't need it now, so I am merely curious as to what I was doing wrong.
Mar 22 '07 #8
Killer42
8,435 Expert 8TB
Killer42, thanks for the great advice. I forgot that I could set hotkeys on the label and through proper setting of the tab order have the hotkey send the user to the textbox. It works perfectly! You saved me a ton of programming throughout the system.
Glad it helped. :)

KSCMJO's solution looked like exactly what I wanted, but I couldn't get it to work. That's why I posted my question. Basically, when I held the Alt key down, the keypress event would never fire. So I only got the keydown part to work. But I don't need it now, so I am merely curious as to what I was doing wrong.
So am I. Haven't played with this stuff in some time. I thought the code looked alright, but don't think I considered the effect of the Alt key.
Mar 23 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Leo | last post by:
hi there i want python to do a beep. in the docu i found in tkinter the method bell() but the script: import Tkinter Tkinter.bell() gives the error:
5
by: Ike | last post by:
Is there wa way to make the system beep (ascii 007...bell) via javascript (or any other simple notification sound)? Thanks, Ike
19
by: Anon Email | last post by:
Hi everyone, Let's see, now. This question is about the capabilities of ANSI C++. I want to write and compile code in ANSI C++ that, when compiled, will make the computer speaker beep; or, at...
8
by: Marcia Gulesian | last post by:
How can I create a beep in javascript (I.E. 5.5 +) ?
3
by: QA | last post by:
When the page is refreshed/reloaded, Mozzila or Opera are fine, but in IE, it has a Beep Sound. Is there a way to turn it off from JS or serverside?
0
by: Rudolf Bargholz | last post by:
Hi all, Windows XP / Windows 2000 DB2 7.1 FP3 WG Server For some strange reason one of our server installations on Windows 2000, and now my Windows XP also, where DB2 WGE 7.1 FP3 is...
9
by: jgcrawford | last post by:
G'day, I'm writing a ringtone manager for nokia ringtones and I'd like to be able to play the ringtone on the PC speaker. I've had some success in DOS with turbo C and its sound(), delay() and...
5
by: John Lee | last post by:
Hi, It's anoying each time the computer beeps when MessageBox.Show() popsup - I turned off all sound in control panel - audio setting but it still beeps. Can anyone help? Thanks! John
6
by: fripper | last post by:
Is it possible to display a message box (using the MSGBOX function) without the beep? Thanks.
4
by: =?Utf-8?B?UmljaA==?= | last post by:
When I press the Enter key in a Textbox I get a beep sound. But when I press the Enter key in a combobox, I don't get the beep sound. Is there a way to suppress the beep? How to do this? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.