ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Playing a sound base on cell value (https://www.excelbanter.com/excel-programming/282636-playing-sound-base-cell-value.html)

Mike[_58_]

Playing a sound base on cell value
 
Hello all,

I have an excel sheet that updates every 2 seconds from an
SQL server that is fed by a PLC. I am monitoring the speed
of a manufacturing line. I want a wave file to play if the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike

immanuel[_2_]

Playing a sound base on cell value
 
You might consider declaring a global variable in your module that contains
the reference of the last cell on which your code beeped. Then, in your
sub, check to see if it's trying to beep on the same cell. If it is the
same cell, just skip the beep. If not, beep, and then set the variable to
the current cell on which it's beeping.

For something specific to your code, post your code.

/i.

"Mike" wrote in message
...
Hello all,

I have an excel sheet that updates every 2 seconds from an
SQL server that is fed by a PLC. I am monitoring the speed
of a manufacturing line. I want a wave file to play if the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike




John Wilson

Playing a sound base on cell value
 
Mike,

Take a look he
http://j-walk.com/ss/excel/tips/tip87.htm

John

"Mike" wrote in message
...
Hello all,

I have an excel sheet that updates every 2 seconds from an
SQL server that is fed by a PLC. I am monitoring the speed
of a manufacturing line. I want a wave file to play if the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike




Mike[_58_]

Playing a sound base on cell value
 
John,
Thanks a bunch. I've been through the tips on JW's
site and only remember the generic sound tip.

Thanks for the redirect,

Mike

-----Original Message-----
Mike,

Take a look he
http://j-walk.com/ss/excel/tips/tip87.htm

John

"Mike" wrote in

message
...
Hello all,

I have an excel sheet that updates every 2 seconds from

an
SQL server that is fed by a PLC. I am monitoring the

speed
of a manufacturing line. I want a wave file to play if

the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike



.


Mike[_58_]

Playing a sound base on cell value
 

-----Original Message-----
You might consider declaring a global variable in your

module that contains
the reference of the last cell on which your code

beeped. Then, in your
sub, check to see if it's trying to beep on the same

cell. If it is the
same cell, just skip the beep. If not, beep, and then

set the variable to
the current cell on which it's beeping.

For something specific to your code, post your code.

/i.

"Mike" wrote in

message
...
Hello all,

I have an excel sheet that updates every 2 seconds from

an
SQL server that is fed by a PLC. I am monitoring the

speed
of a manufacturing line. I want a wave file to play if

the
line stops (cell value=0). I found the code for calling
sounds, but how do I get it to play once, after the cell
equals 0? I assume the code would be similar to play a
different sound when the line starts back up again?

Windows 2000
Excel 2000

Thanks,
Mike



.

'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "\go.wav" 'Edit this
statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or
SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

function is
=Alarm(A3,"D2=0")


All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com