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 Sub Form_Load()
Text1.Text = "1 2 3 4"
End Sub
Private Sub Command1_Click()
Dim inputText As String '输入的文本
Dim inputArr() As String '输入的数字数组
Dim i As Integer '循环计数器
Timer1.Interval = 100
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
Case 2
Beep 1200, 300 '播放1200Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\2.jpeg") '显示图片2
Case 3
Beep 1600, 300 '播放1600Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\3.jpeg") '显示图片3
Case 4
Beep 2500, 300 '播放1600Hz的蜂鸣声,持续100毫秒
Image1.Picture = LoadPicture("C:\Users\28261\Desktop\4.jpeg") '显示图片4
Case Else
MsgBox "无法识别的数字"
Exit Sub '如果遇到无法识别的数字,退出循环
End Select
'加入延迟以便观察效果
Dim endTime As Single, currentTime As Single
endTime = Timer + 0.01 '设置延迟0.01秒
Do While Timer < endTime
DoEvents
Loop
Next i
End Sub
Private Sub Command2_Click()
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
Call Command1_Click
End Sub