Stopping Default Sound from Playing

G

Guest

I have an application that is designed for using with a bar code scanner. I
want the user to know that the scan was complete and the data was entered, so
I am playing a system sound after data entry. The data is being put into a
text box, and a Return is sent after the data. I use the keypress event to
capture the Return, and save the data. Then, I play the system sound, clear
the text box, and set the focus back to the text box for the next entry.
When I do that, somewhere along the way, the default sound also plays. This
is disrupting my Exclamation sound, and not giving the audible notification
that I want. If there is a problem with the input for some reason, then I
have a message box popping up, and it gives the default sound also. Changing
the default sound does no good, as it would change the one being played when
the message box pops up. The user will not have anything to distinguish
between the good input and the bad input. What event is firing the default
sound, and can I turn it off, so that my Exclamation sound can be heard, or
can I set it to the Exclamation sound?
 
M

Mehdi

I have an application that is designed for using with a bar code scanner. I
want the user to know that the scan was complete and the data was entered, so
I am playing a system sound after data entry. The data is being put into a
text box, and a Return is sent after the data. I use the keypress event to
capture the Return, and save the data. Then, I play the system sound, clear
the text box, and set the focus back to the text box for the next entry.
When I do that, somewhere along the way, the default sound also plays. This
is disrupting my Exclamation sound, and not giving the audible notification
that I want. If there is a problem with the input for some reason, then I
have a message box popping up, and it gives the default sound also. Changing
the default sound does no good, as it would change the one being played when
the message box pops up. The user will not have anything to distinguish
between the good input and the bad input. What event is firing the default
sound, and can I turn it off, so that my Exclamation sound can be heard, or
can I set it to the Exclamation sound?

For your second problem (exclamation sound when the MessageBox is shown),
simply do not show a MessageBox if you do not want any sound to play.
Instead, create your own Form (you can make it look like the standard
MessageBox and implement static methods to show it if you want, it's all
straightforward) and show that instead. It won't play any sound.

Regarding your first problem, it isn't clear from your description why the
exclamation sound is played. Find out what exactly causes the default sound
to play and don't do that (just as with the MessageBox, find an alternative
way of doing whatever you want to do).
 
G

Guest

The only thing that I can find is that the sound plays when I exit the
KeyPress event method. I have stepped my code, and I get no default sound
until I execute the Exit Sub line. I have no idea what is causing the
default sound.
 
M

Mehdi

The only thing that I can find is that the sound plays when I exit the
KeyPress event method. I have stepped my code, and I get no default sound
until I execute the Exit Sub line. I have no idea what is causing the
default sound.

If you're using a single-line textbox (ie. Multiline is set to false), then
pressing the Return key in the text box will cause Windows to emit a beep,
presumably to inform the user that they can't create new lines in the text
box.

It is not very clear what you are doing with your text box. From your
original description, it looks like the user is not actually typing
anything in the text box but that you're reading data using a bar code
reader, populating the textbox with the read data then insterting a Return
caracter at the end. And on top of that you're using the keypress event to
do I don't know what. I have trouble understanding what you are trying to
achieve. Why do you need to insert a Return caracter at the end of the data
in the text box? This caracter can not be seen anyway since it's a
single-line textbox so what's the point of adding it? If you don't add the
Return at the end, Windows won't beep.
 
G

Guest

The barcode scanner acts like a keyboard. The data is entered by the barcode
scanner. To all intents and purposes, the program can not tell the
difference between a scan from the barcode scanner, and input from the
keyboard. The Return character is sent by the barcode scanner to indicate
that the barcode is complete. If it is the Return that is causing the
problem, then I possibly could change the Return character to something else,
so that I could test for that character instead. The Return currently tells
the program that the barcode is complete, and to process that barcode, by
creating a new row in the data table, and populating the row with the
barcode, and other data from the input screen.

Since I don't have the scanner in my possession to reprogram it, is there
any way to turn this beep off?
 
M

Mehdi

The barcode scanner acts like a keyboard. The data is entered by the barcode
scanner. To all intents and purposes, the program can not tell the
difference between a scan from the barcode scanner, and input from the
keyboard. The Return character is sent by the barcode scanner to indicate
that the barcode is complete. If it is the Return that is causing the
problem, then I possibly could change the Return character to something else,
so that I could test for that character instead. The Return currently tells
the program that the barcode is complete, and to process that barcode, by
creating a new row in the data table, and populating the row with the
barcode, and other data from the input screen.

Since I don't have the scanner in my possession to reprogram it, is there
any way to turn this beep off?

Alright, I get it now. Well, I see 2 solutions:

- turning the beep off. There are hacks that allow you to turn it off
without modifying the system sound settings. I did it a while ago though
can't remember exactly what I did. However if you search Google Groups for
Textbox Return (or Enter) Beep, you'll find a lot of discusions about this.
You shouldn't have too much troubles switching off the beep.

- Set a default Accept button on your form. If your form has a default
Accept button, pressing Enter while in the textbox will press this button
instead of doing nothing and beeping. So you could maybe have an OK button
set as the Accept button of your form which, when pressed, would add the
new data in the datatable. Actually, using an Accept button will introduce
other problems (it will by default automatically set the DialogResult value
of your form which will cause it to close if it has been shown modally) so
if you've got your program already done and working the way you want the
best solution would probably be to just switch off the beeping sound
following Google Groups suggestions.
 
G

Guest

Thanks for the tip. Searching as you suggesting yielded the suggestion to
add the following line to my code that handled the Return keypress:

e.handled=True

That did it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top