Set Bell, Set("Bell")

SET BELL can be toggled to determine if you want to annoy your end users endlessly and drive them to an early grave by beeping at them when they reach the end of a field. To further annoy them, you can change the bell's exact sound (or the sound file it plays) as well. The chosen sound is also played when the CHR(7) character is displayed to the screen.

Usage

SET BELL ON | OFF
SET BELL TO [ nFreq, nSeconds ]    && MS-DOS version
SET BELL TO [ cWavFile, nNothing ] && Windows, VFP 3 & 5 version
SET BELL TO [ cWavFile ]           && VFP 6 and later, at last!
cBellOnOff = SET( "BELL" )
cWavFile = SET( "BELL" , 1 )

Parameter

Value

Meaning

nFreq

Numeric

Approximate frequency of the bell sounds, in Hertz, range 19 to 10,000—MS-DOS ONLY!!!

nSeconds

Numeric

Length of time the annoying tone plays, in seconds—MS-DOS ONLY!!!

cWavFile

Character

Name of a sound file, with path if necessary or, in FoxPro/Windows, the name of a pre-defined sound in the [Sound] section of WIN.INI.

nNothing

Numeric

This parameter is ignored, but an error, "Missing expression", occurs if not passed. Useless.

Omitted

 

Restores the bell to its "normal" condition—a bell sound in DOS and the system setting for the bell under Windows.


We have yet to meet an end user who prefers to be beeped at when the normal end of each field is reached. SET BELL OFF!

Prior to VFP 6, there was no way to determine what settings were in place, beyond SET("BELL") returning "ON" or "OFF." VFP 6 introduced SET("BELL",1) to return the name of the WAV file, if one is set.


Two different methods exist for specifying a sound file. You can supply either a specific file name and path, or the name of a Windows event. If you want to play a specific sound file, make sure it exists by using the FILE() function. If you choose to be consistent with other applications, check the user's Registry for the entry you want to use before specifying it. Otherwise, the default system sound (typically a beep, but it also can be changed by the user in Control Panel or Registry) plays. See the Control Panel's Sound applet and the Registry key mentioned below for some ideas and the name of events you might want to hook into.The help files for VFP 3 and 5 were out to lunch when they talked about the [Sounds] entry of WIN.INI as the source of system-event sounds. WIN.INI's old; everything is in the Registry now. Worse, when the Sounds moved to the Registry, we lost the ability to use them natively. "Sound Schemes" are stored in the Registry in all Win32 environments (the only ones in which VFP 5 and later can run) under the key HKEY_CURRENT_USER\AppEvents\Schemes\Apps \.Default. (Note the dot (".") before "Default" in that path.) See the third example below for some ideas for using these.You may want to warn the user that a sound driver must be in place, and give them an option to turn off these sounds. Specifying a WAV file when no driver is available results in no sounds at all.
Example
SET BELL TO "C:\WINNT\MEDIA\TADA.WAV"
?? CHR(07)  && The WAV file is played.
? SET("BELL", 1)  && Returns "C:\WINNT\MEDIA\TADA.WAV"
 
* This is how easy it should be. This works in FPW:
SET BELL TO "SystemExclamation",5
?? CHR(07)  && user-defined sound is played.
 
* This is how easy it is?:
oRegistry = NEWOBJECT("Registry", HOME() + "FFC\REGISTRY.VCX")
HKEY_CURRENT_USER = -2147483647  && BITSET(0,31)+1
cValue = SPACE(255)
oRegistry.GetRegKey("",@cValue,;
 "AppEvents\Schemes\Apps\.Default\SystemExclamation\.Current",;
 HKEY_CURRENT_USER)
IF "\" $ cValue
  * This is an explicit path
  * The Windows\media path is assumed if not supplied
ELSE
  cValue = "C:\WINNT\Media\" + cValue
ENDIF
IF FILE(cValue)
  SET BELL TO cValue
ENDIF
?? CHR(07)

See Also

Chr(), INI Files, Registration Database


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .