Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic 6.0 Code

Status
Not open for further replies.

dlh3334

Technical User
Dec 25, 2000
2
US

How do I change the following code so that the Beep is sounded for ten or more times? Thank you so much.

Don Harris



Private Sub Timer1_Timer()
CurrentTime = Format(Time, "hh:mm")
If CurrentTime = Text1.Text Then
Beep
MsgBox (Text2.Text), , "Personal Alarm"
Timer1.Enabled = False
Form1.WindowState = 0 'Restore form
End If
End Sub
 
Try this...


Private Sub Timer1_Timer()
CurrentTime = Format(Time, "hh:mm")
If CurrentTime = Text1.Text Then
For X = 1 to 10
Beep
Next X
MsgBox (Text2.Text), , "Personal Alarm"
Timer1.Enabled = False
Form1.WindowState = 0 'Restore form
End If
End Sub Gordon R. Durgha
gd@vslink.net
 
If you want the beeps spread out, ;like a real alarm, then add another timer control to sound the beeps, and add some module level variables to control the alarm.

To test out the following, add another timer control to your form, setting the Interval property to the time you want between the beeps (I used 250 for 4 beeps per second) and add he following code.

Option Explicit

Dim bAlarm As Boolean ' True if alarm should sound
Dim lBeepCount As Long ' count of beeps in current alarm sounding
Const lMaxBeep As Long = 10 ' maximum beeps for alarm

Private Sub Timer1_Timer()
Dim CurrentTime As String
Dim x As Integer
CurrentTime = Format(Time, "hh:mm:ss")
If CurrentTime = Text1.Text Then
bAllarm = True ' sound alarm
Timer1.Enabled = False ' don't check again
Form1.WindowState = 0 'Restore form
End If
End Sub

Private Sub Timer2_Timer()
If bAllarm = True Then ' check alarm is activated
lBeepCount = lBeepCount + 1 ' increase count
Beep ' sound the alarm
If lBeepCount = lMaxBeep Then ' should alarm finish
bAllarm = False ' deactivate alarm
MsgBox (Text2.Text), , "Personal Alarm" ' show message
End If
End If
End Sub


Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top