Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Dim inputText As String '输入的文本
Dim inputArr() As String '输入的数字数组
Dim i As Integer '循环计数器
inputText = Text1.Text '获取输入的文本
' 将所有空格替换为逗号,将文本转换为数组
inputArr = Split(Replace(inputText, " ", ","), ",")
For i = LBound(inputArr) To UBound(inputArr)
Select Case Val(inputArr(i))
Case 1
Beep 800, 300 '播放800Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\1.jpeg") '显示图片1
PlaySound "C:\Users\28261\Desktop\o.wav" '播放声音1
Case 2
Beep 1200, 300 '播放1200Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\2.jpeg") '显示图片2
PlaySound "C:\Users\28261\Desktop\p.wav" '播放声音2
Case 3
Beep 1600, 300 '播放1600Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\3.jpeg") '显示图片3
PlaySound "C:\Users\28261\Desktop\q.wav" '播放声音3
Case Else
MsgBox "无法识别的数字"
Exit Sub '如果遇到无法识别的数字,退出循环
End Select
'加入延迟以便观察效果
Dim endTime As Single, currentTime As Single
endTime = Timer + 1 '设置延迟1秒
Do While Timer < endTime
DoEvents
Loop
Next i
End Sub
Private Sub PlaySound(ByVal soundFilePath As String)
Dim command As String
command = "open " & Chr(34) & soundFilePath & Chr(34) & " type MPEGVideo alias mySound"
mciSendString command, "", 0, 0
command = "play mySound"
mciSendString command, "", 0, 0
End Sub