Public Class Form1
Private dt As DateTime
Private sound As String
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
TextBox2.Text = TextBox1.Text
TextBox3.Text = TextBox1.Text
TextBox4.Text = TextBox1.Text
TextBox5.Text = TextBox1.Text
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer4.Interval = 1000
sound = Application.StartupPath & "\dongshi.mp3"
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If IsTime(TextBox2.Text) = False Then
MsgBox("不是正确时间格式")
TextBox2.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "停止" Then
Button1.Text = "启动"
Call mciSendString("stop MySound", "", 0, 0)
Call mciSendString("close MySound", "", 0, 0)
Else
Timer1.Start()
Timer2.Start()
Timer3.Start()
Timer4.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
Me.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
dt = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
If dt = TextBox2.Text Then
Button1.Text = "停止"
Call mciSendString(String.Format("open ""{0}"" alias MySound", sound), "", 0, 0)
Call mciSendString("play MySound", "", 0, 0)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ofd As New OpenFileDialog()
ofd.FileName = ""
'ofd.InitialDirectory = "C:\"
ofd.Filter = _
"mp3文件(*.mp3)|*.mp3|wave文件(*.wave)|*.wave|mid文件(*.mid)|*.mid"
ofd.FilterIndex = 1
ofd.Title = "请选择音乐"
ofd.RestoreDirectory = True
ofd.CheckFileExists = True
ofd.CheckPathExists = True
If ofd.ShowDialog() = DialogResult.OK Then
sound = ofd.FileName
End If
End Sub
Public Function IsTime(ByVal S As String) As Boolean
'On Error GoTo Err
Dim i As Date
Try
i = CDate(S)
Catch ex As Exception
IsTime = False
Exit Function
End Try
If InStr(S, "/") <> 0 Then
IsTime = False
ElseIf InStr(S, ":") = 0 Then
IsTime = False
'ElseIf Int(i) <> 0 Then
' IsTime = False
Else
IsTime = True
End If
'Exit Function
'Err:
' IsTime = False
End Function
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
TextBox1.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
Me.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
dt = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
If dt = TextBox3.Text Then
Button1.Text = "停止"
Call mciSendString(String.Format("open ""{0}"" alias MySound", sound), "", 0, 0)
Call mciSendString("play MySound", "", 0, 0)
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
TextBox1.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
Me.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
dt = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
If dt = TextBox4.Text Then
Button1.Text = "停止"
Call mciSendString(String.Format("open ""{0}"" alias MySound", sound), "", 0, 0)
Call mciSendString("play MySound", "", 0, 0)
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
TextBox1.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
Me.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
dt = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
If dt = TextBox5.Text Then
Button1.Text = "停止"
Call mciSendString(String.Format("open ""{0}"" alias MySound", sound), "", 0, 0)
Call mciSendString("play MySound", "", 0, 0)
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If IsTime(TextBox3.Text) = False Then
MsgBox("不是正确时间格式")
TextBox3.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
End If
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If IsTime(TextBox4.Text) = False Then
MsgBox("不是正确时间格式")
TextBox4.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
End If
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If IsTime(TextBox5.Text) = False Then
MsgBox("不是正确时间格式")
TextBox5.Text = Format("ToLongTimeString :{0}", DateTime.Now.ToLongTimeString())
End If
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
End Sub
End Class