Creating Audible Alarm in ProcessBook

Discussion created by Blaise on Mar 25, 2020

Hi everyone,


I have implemented the following code from an article I found into VBA to create an audible alarm in Process Book. In testing, the multistate will change color once the state is changed, however, the subroutine that handles the triggering of the alarm seems to be skipped.


Does anyone have a clue as to why the sound will not go off?


' Declaration
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

' Declaration for playing sound

Private Const SND_ASYNC = &H1
Private Const SND_LOOP = &H8
Private Const SND_MEMORY = &H4
Private Const SND_NODEFAULT = &H2
Private Const SND_NOSTOP = &H10
Private Const SND_SYNC = &H0
Private Const SND_ALIAS = &H10000
Private Const SND_APPLICATION = &H80
Private Const SND_ALIAS_ID = &H110000
Private Const SND_FILENAME = &H20000
Private Const SND_NOWAIT = &H2000
Private Const SND_PURGE = &H40
Private Const SND_RESOURCE = &H40004

' This method takes care of playing the alarm (5 times). Trying higher number may hurt and PI ProcessBook may even crash.
Sub Play_Sound()
Dim x As Integer

For x = 1 To 5
Dim sAlert1 As String
sAlert1 = "notify.wav"
PlaySound sAlert1, 0, &H0
Next x
End Sub

' This method converts the multistate symbol to static before closing the display file.
Private Sub Display_BeforeClose(bCancelDefault As Boolean)
End Sub

' Display open method creates the multistate on a static Ellipse/Rectangle symbol
Private Sub Display_Open()
Dim oRectangle As Rectangle
Dim oMultiState As MultiState
Dim oMSState As MSState

'Symbols(2) corresponds with the rectangle symbol in the display
Set oRectangle = ThisDisplay.Symbols(2)
Set oMultiState = oRectangle.CreateMultiState("PB_Audible_Alarm_Test")
oMultiState.StateCount = 2
oMultiState.DefineState 2, 0, 10

' Declaring state 1
Set oMSState = oMultiState.GetState(1)
oMSState.DefineState 0, 5, pbGreen

' Declaring state 2
Set oMSState = oMultiState.GetState(2)
oMSState.DefineState 5, 10, pbRed
End Sub


' State change event fires the Play_Sound() for the audible alarms.
Private Sub Rectangle1_StateChanged(bCancelDefault As Boolean)
End Sub


Thanks for your time,