Visual Basic for Applications/Variable Beep from VBA

Summary
'''This VBA code module examines various uses of the Beep API. Its parameters are frequency and duration. It has no wait parameter, so chords are not possible, just simple tones. It is stated to work well for Windows 7 versions onwards, but might ignore the parameters for earlier versions. Simple musical scales and tunes are illustrated, in addition to a Morse code text sender'''.

Beep API Bugs
In the past many problems were found in the use of the Beep API. Since Windows 7, the Beep API has been re-coded by Microsoft to work with computer sound cards. Prior to Windows 7, the API functioned only with an on-board sound chip. Unfortunately, during the transition from sound chips to sound cards, some computer manufacturers still used chips while others used cards. This is the basis of the problem for older Windows versions. No problems should be encountered in the use of the Beep API for recent builds.

Procedure Notes
Several procedures are provided in the module. Copy the entire code into a standard module for testing. The procedures are as follows:
 * Beeper is the basic form of the function. Running it will make a simple tone in the computer's speakers. Note that it does not refer to the alert sounder that is built into Windows, but the speakers used for listening to media.  Both the frequency and duration of the sound can be adjusted, though the consistency of the output, being designed for selected frequency use is not very good.
 * TestNotes expands on the basic format. Run this to produce up and down scales.   There are two ways to access frequencies:
 * The first is just to enter the exact frequencies for each note in a sequence of code lines; this is the case for the do re me scales, the so-called natural notes, eg, C,D,E,F,G,A,B,C....
 * The other, when the exact frequencies are not known is to use a formula to calculate the frequency based on knowledge of the relative position of the note with respect to a reference point. (See Figures 1 and 2).  The reference point in this case is note A = 440 Hz.   Figure 1 shows three octaves of notes around 440Hz, and Figure 2 shows how notes in a simple music score relate to note distance. The note-distance value can be used to calculate frequency for any other note. For example, in Figure 2, notice that the G notes have a distance of 10; this and all other note distances are listed in the table of Figure 1.  When it is understood that G notes always occupy the second line of the treble clef, a simple score can be marked with both notes and distances, ready for coding.
 * SendMorse sounds out the Morse code for a parameter string. The procedure gives a basic output, with adjustable frequency (Hz) and dot length (milliseconds).
 * Delays are introduced with Delay  for the inter-element (one dot), inter-character (3 dots), and inter-word (7 dots) intervals, in addition to the basic one to three ratio for dots and dashes.  All timing is derived from the length of one short dot element. A random element can be added to all timing in Random, where the maximum percentage of error can be set; this is said to better resemble a human hand rather that the too-perfect program.
 * The convention is to estimate words per minute  in terms of dot duration also, as T = 1200 / W where T is dot duration in milliseconds and W is the generated number of words per minute. The international Morse code is given for reference in Figure 3.

The Code
Run TestBeeper, TestNotes, or testSendMorse to run the various procedures.
 * Modified 24 Dec 18 to add randomness to all timing in SendMorse
 * Modified 24 Dec 18 to add an omitted sCode declaration in SendMorse
 * Modified 23 Dec 18 to correct data in SendMorse array vSN
 * Modified 22 Dec 18 to show use of note distance in a tune.
 * Modified 21 Dec 18 to correct timing errors for Morse code procedures.