Work has been a little slow so....

Comfy

Well-known Member
Joined
Dec 21, 2009
Messages
3,377
I was bored in work the other day and so started building some songs that utilised the Beep function.

We still have XP in work so they play as intended. Since Vista + no longer use motherboard beeps and instead use the default sound card they may not play very well.

Code:
Public Declare Function Beep Lib "kernel32" _
   (ByVal dwFreq As Long, _
    ByVal dwDuration As Long) As Long
Option Explicit


Public CShp0 As Double, CShp1 As Double, CShp2 As Double, CShp3 As Double, CShp4 As Double, CShp5 As Double, CShp6 As Double, CShp7 As Double, CShp8 As Double
Public DShp0 As Double, DShp1 As Double, DShp2 As Double, DShp3 As Double, DShp4 As Double, DShp5 As Double, DShp6 As Double, DShp7 As Double, DShp8 As Double
Public FShp0 As Double, FShp1 As Double, FShp2 As Double, FShp3 As Double, FShp4 As Double, FShp5 As Double, FShp6 As Double, FShp7 As Double, FShp8 As Double
Public GShp0 As Double, GShp1 As Double, GShp2 As Double, GShp3 As Double, GShp4 As Double, GShp5 As Double, GShp6 As Double, GShp7 As Double, GShp8 As Double
Public AShp0 As Double, AShp1 As Double, AShp2 As Double, AShp3 As Double, AShp4 As Double, AShp5 As Double, AShp6 As Double, AShp7 As Double, AShp8 As Double
Public C0 As Double, C1 As Double, C2 As Double, C3 As Double, C4 As Double, C5 As Double, C6 As Double, C7 As Double, C8 As Double
Public D0 As Double, D1 As Double, D2 As Double, D3 As Double, D4 As Double, D5 As Double, D6 As Double, D7 As Double, D8 As Double
Public E0 As Double, E1 As Double, E2 As Double, E3 As Double, E4 As Double, E5 As Double, E6 As Double, E7 As Double, E8 As Double
Public F0 As Double, F1 As Double, F2 As Double, F3 As Double, F4 As Double, F5 As Double, F6 As Double, F7 As Double, F8 As Double
Public G0 As Double, G1 As Double, G2 As Double, G3 As Double, G4 As Double, G5 As Double, G6 As Double, G7 As Double, G8 As Double
Public A0 As Double, A1 As Double, A2 As Double, A3 As Double, A4 As Double, A5 As Double, A6 As Double, A7 As Double, A8 As Double
Public B0 As Double, B1 As Double, B2 As Double, B3 As Double, B4 As Double, B5 As Double, B6 As Double, B7 As Double, B8 As Double


Public Breve As Double, SemiBreve As Double, Minim As Double, Crotchet As Double, Quaver As Double, SemiQuaver As Double


Function SetNotes()
C0 = 16.35: CShp0 = 17.32: D0 = 18.35: DShp0 = 19.45: E0 = 20.6: F0 = 21.83: FShp0 = 23.12: G0 = 24.5: GShp0 = 25.96: A0 = 27.5: AShp0 = 29.14: B0 = 30.87
C1 = 32.7: CShp1 = 34.65: D1 = 36.71: DShp1 = 38.89: E1 = 41.2: F1 = 43.65: FShp1 = 46.25: G1 = 49: GShp1 = 51.91: A1 = 55: AShp1 = 58.27: B1 = 61.74
C2 = 65.41: CShp2 = 69.3: D2 = 73.42: DShp2 = 77.78: E2 = 82.41: F2 = 87.31: FShp2 = 92.5: G2 = 98: GShp2 = 103.83: A2 = 110: AShp2 = 116.54: B2 = 123.47
C3 = 130.81: CShp3 = 138.59: D3 = 146.83: DShp3 = 155.56: E3 = 164.81: F3 = 174.61: FShp3 = 185: G3 = 196: GShp3 = 207.65: A3 = 220: AShp3 = 233.08: B3 = 246.94
C4 = 261.63: CShp4 = 277.18: D4 = 293.66: DShp4 = 311.13: E4 = 329.63: F4 = 349.23: FShp4 = 369.99: G4 = 392: GShp4 = 415.3: A4 = 440: AShp4 = 466.16: B4 = 493.88
C5 = 523.25: CShp5 = 554.37: D5 = 587.33: DShp5 = 622.25: E5 = 659.25: F5 = 698.46: FShp5 = 739.99: G5 = 783.99: GShp5 = 830.61: A5 = 880: AShp5 = 932.33: B5 = 987.77
C6 = 1046.5: CShp6 = 1108.73: D6 = 1174.66: DShp6 = 1244.51: E6 = 1318.51: F6 = 1396.91: FShp6 = 1479.98: G6 = 1567.98: GShp6 = 1661.22: A6 = 1760: AShp6 = 1864.66: B6 = 1975.53
C7 = 2093: CShp7 = 2217.46: D7 = 2349.32: DShp7 = 2489.02: E7 = 2637.02: F7 = 2793.83: FShp7 = 2959.96: G7 = 3135.96: GShp7 = 3322.44: A7 = 3520: AShp7 = 3729.31: B7 = 3951.07
C8 = 4186.01: CShp8 = 4434.92: D8 = 4698.63: DShp8 = 4978.03: E8 = 5274.04: F8 = 5587.65: FShp8 = 5919.91: G8 = 6271.93: GShp8 = 6644.88: A8 = 7040: AShp8 = 7458.62: B8 = 7902.13
End Function


Sub SetLengths(BPM As Long)
Crotchet = (60 / BPM) * 1000
Breve = Crotchet * 8
SemiBreve = Crotchet * 4
Minim = Crotchet * 2
Quaver = Crotchet / 2
SemiQuaver = Crotchet / 4
End Sub
'http://www.phy.mtu.edu/~suits/notefreqs.html
Sub HappyBirthday()


SetNotes
SetLengths (120) 'requires BPM


Beep D5, Quaver 'D
Beep D5, Quaver 'D
Beep E5, Crotchet 'E
Beep D5, Crotchet 'D
Beep G5, Crotchet 'G
Beep FShp5, Minim 'F#
Beep D5, Quaver 'D
Beep D5, Quaver 'D
Beep E5, Crotchet 'E
Beep D5, Crotchet 'D
Beep A5, Crotchet   'A
Beep G5, Minim 'G
Beep D5, Quaver 'D
Beep D5, Quaver 'D
Beep D6, Crotchet 'D
Beep B5, Crotchet 'B
Beep G5, Crotchet 'G
Beep FShp5, Crotchet 'F#
Beep E5, Crotchet 'E
Beep C6, Quaver 'C
Beep C6, Quaver 'C
Beep B5, Crotchet 'B
Beep G5, Crotchet 'G
Beep A5, Crotchet   'A
Beep G5, Minim 'G
End Sub
Sub YaketySax()


Call SetNotes
SetLengths (160) 'requires BPM


Beep D6, Quaver + SemiQuaver 'D
Beep E6, SemiQuaver 'E
Beep G6, Quaver 'G
Beep G6, Quaver 'G
Beep E6, SemiQuaver 'E
Beep D6, SemiQuaver 'D
Beep G5, SemiQuaver 'G
Beep B5, SemiQuaver 'B
Beep D6, SemiQuaver 'D
Beep B5, SemiQuaver 'B
Beep E6, Quaver 'E
Beep D6, SemiQuaver 'D
Beep B5, SemiQuaver 'B
Beep A5, SemiQuaver   'A
Beep B5, SemiQuaver 'B
Beep G5, Quaver 'G
Beep A5, SemiQuaver   'A
Beep AShp5, SemiQuaver   'A#
Beep B5, SemiQuaver 'B
Beep D6, SemiQuaver 'D
Beep E6, SemiQuaver 'E
Beep D6, SemiQuaver 'D
Beep G6, Crotchet + SemiQuaver 'D
Beep D6, SemiQuaver 'D
Beep E6, SemiQuaver 'E
Beep D6, SemiQuaver 'D
Beep G6, Quaver 'G
Beep G6, Quaver 'G
Beep E6, SemiQuaver 'E
Beep D6, SemiQuaver 'D
Beep G5, SemiQuaver 'G
Beep B5, SemiQuaver 'B
Beep D6, SemiQuaver 'D
Beep B5, SemiQuaver 'B
Beep E6, Quaver 'E
Beep D6, SemiQuaver 'D
Beep B5, SemiQuaver 'B
Beep G5, SemiQuaver 'G
Beep B5, SemiQuaver 'B
Beep D6, Quaver 'D
Beep D6, SemiQuaver 'D
Beep D6, SemiQuaver 'D
Beep FShp6, SemiQuaver 'F#
Beep A6, SemiQuaver   'A
Beep FShp6, Quaver 'F#
Beep D6, Crotchet + SemiQuaver 'D
Beep D6, SemiQuaver 'D
Beep E6, SemiQuaver 'E
Beep D6, SemiQuaver 'D
Beep G6, Quaver 'G
Beep G6, SemiQuaver 'G
Beep G6, SemiQuaver 'G
Beep G6, Quaver 'G
Beep G6, SemiQuaver 'G
Beep G6, SemiQuaver 'G
Beep G6, Quaver 'G
Beep G6, Quaver 'G
Beep E6, SemiQuaver 'E
Beep D6, Quaver + SemiQuaver 'D
Beep C6, Quaver  'C
Beep C6, Quaver  'C
Beep C6, Quaver  'C
Beep C6, Quaver  'C
Beep E6, SemiQuaver 'E
Beep G6, SemiQuaver 'G
Beep A6, SemiQuaver   'A
Beep G6, SemiQuaver 'G
Beep AShp6, SemiQuaver 'A#
Beep G6, Quaver 'G
Beep AShp6, SemiQuaver 'A#
Beep B6, SemiQuaver 'B
Beep AShp6, SemiQuaver 'A#
Beep B6, SemiQuaver 'B
Beep AShp6, SemiQuaver 'A#
Beep B6, SemiQuaver 'B
Beep D7, Quaver 'D
Beep AShp6, SemiQuaver 'A#
Beep B6, SemiQuaver 'B
Beep D7, SemiQuaver 'D
Beep B6, Quaver 'B
Beep G6, Quaver 'G
Beep D6, Quaver 'D
Beep E7, SemiQuaver 'E
Beep B6, Quaver 'B
Beep D6, SemiQuaver 'D
Beep A6, Quaver   'A
Beep G6, Quaver 'G


End Sub
Sub LooneyTunes()
Call SetNotes
SetLengths (165) 'requires BPM


Beep E5, Quaver + SemiQuaver
Beep D5, SemiQuaver
Beep C5, Quaver
Beep D5, Quaver
'---------------
Beep E5, Quaver
Beep DShp5, Quaver
Beep E5, Quaver
Beep C5, Quaver
'---------------
Beep D5, Quaver
Beep D5, Quaver
Beep D5, Quaver
Beep D5, Quaver + Minim
'---------------
Beep D5, Quaver + SemiQuaver
Beep C5, SemiQuaver
Beep B5, Quaver
Beep C5, Quaver
'---------------
Beep D5, Quaver
Beep CShp5, Quaver
Beep D5, Quaver
Beep B5, Quaver
'---------------
Beep C5, Quaver
Beep C5, Quaver
Beep C5, Quaver
Beep C5, Quaver + Minim
'---------------
Beep G4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
Beep A4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
'---------------
Beep G4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
Beep A4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
'---------------
Beep G4, Quaver
Beep D5, Quaver
Beep D5, Quaver
Beep D5, Quaver + Minim
'---------------
Beep G4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
Beep A4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
'---------------
Beep G4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
Beep A4, Quaver + SemiQuaver
Beep GShp4, SemiQuaver
'---------------
Beep G4, Quaver
Beep E5, Quaver
Beep E5, Quaver
Beep E5, Quaver + Minim
'---------------
Beep E6, Quaver + SemiQuaver
Beep D6, SemiQuaver
Beep C6, Quaver
Beep D6, Quaver
'---------------
Beep E6, Quaver
Beep DShp6, Quaver
Beep E6, Quaver
Beep C6, Quaver
'---------------
Beep D6, Quaver
Beep D6, Quaver
Beep D6, Quaver
Beep D6, Crotchet + Minim
'---------------
Beep GShp4, Quaver
Beep A4, Quaver
Beep D5, Crotchet + Quaver
'---------------
Beep E5, Crotchet
Beep G5, Crotchet + Minim
End Sub

It's been quite amusing adding the code to the workbook_open event and sending it to colleagues. :ROFLMAO:
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Watch MrExcel Video

Forum statistics

Threads
1,108,984
Messages
5,526,060
Members
409,682
Latest member
HisHailo

This Week's Hot Topics

Top