Consulting

Results 1 to 2 of 2

Thread: add a condition

  1. #1
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location

    add a condition

    I am using the current code as an alert for real time P&L on my trading account. If it exceeds a certain limit it triggers a sound and email alert.
    However I would like to add the option of turning off the sound alert. How can I add an extra condition to just the sound alert part without affecting the email alert section?

    Thanks in advance

    [VBA]
    Private Sub Worksheet_Calculate()
    Dim tf As Boolean, soundFile As String
    Dim myVal As Double

    If IsError(Range("B4")) Then
    myVal = 0
    Else
    myVal = Range("B4").Value
    End If



    If myVal <= Range("G3").Value And Range("H3").Value <> "Limit" Then
    Application.EnableEvents = False
    Range("H3").Value = "Limit"
    Application.EnableEvents = True
    soundFile = "C:\tt\sounds\alarm2.wav"
    Call sndPlaySound32(soundFile, SND_LOOP Or SND_ASYNC)
    Call CDO_Mail_Small_Text_2


    If MsgBox("Level I !!", vbOKOnly Or vbQuestion) = vbOK Then
    Call sndPlaySound32(0&, 1&)
    End If
    End If

    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Calculate()
    Dim tf As Boolean, soundFile As String
    Dim myVal As Double

    If IsError(Range("B4")) Then
    myVal = 0
    Else
    myVal = Range("B4").Value
    End If



    If myVal <= Range("G3").Value And Range("H3").Value <> "Limit" Then
    Application.EnableEvents = False
    Range("H3").Value = "Limit"
    Application.EnableEvents = True
    soundFile = "C:\tt\sounds\alarm2.wav"
    If Me.Range("H1").Value = "No" Then 'change to suit <<<<<<<<<<<<<<<<<

    Call sndPlaySound32(soundFile, SND_LOOP Or SND_ASYNC)
    End If

    Call CDO_Mail_Small_Text_2


    If MsgBox("Level I !!", vbOKOnly Or vbQuestion) = vbOK Then
    Call sndPlaySound32(0&, 1&)
    End If
    End If
    End Sub [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •