Private Sub Command3_Click()
Dim s1 As String
Dim s2 As String
Dim i As Integer
Dim midiNote1 As Integer
Dim midiNote2 As Integer
s1 = Text1.Text
s2 = Text2.Text '假设第二个文本框的名称为 Text2
For i = 1 To Len(s1) Or Len(s2) '取两个字符串长度中的较大值作为循环次数
Dim note1 As String
Dim note2 As String
If i <= Len(s1) Then
note1 = Mid(s1, i, 1)
Else
note1 = "" '如果第一个字符串结束了,设置为空字符串
End If
If i <= Len(s2) Then
note2 = Mid(s2, i, 1)
Else
note2 = "" '如果第二个字符串结束了,设置为空字符串
End If
Select Case note1
Case "1"
midiNote1 = 23
Case "2"
midiNote1 = 34
Case "3"
midiNote1 = 36
Case "4"
midiNote1 = 38
Case "5"
midiNote1 = 40
Case "6"
midiNote1 = 42
Case "7"
midiNote1 = 44
Case Else
midiNote1 = 0
End Select
Select Case note2
Case "1"
midiNote2 = 23
Case "2"
midiNote2 = 34
Case "3"
midiNote2 = 36
Case "4"
midiNote2 = 38
Case "5"
midiNote2 = 40
Case "6"
midiNote2 = 42
Case "7"
midiNote2 = 44
Case Else
midiNote2 = 0
End Select
If midiNote1 > 0 Then
Call note_on(0, midiNote1 + Sta, sudu) '使用 note_on 过程播放音符
Else
Call note_off(0, 0) '如果没有音符,停止播放
End If
If midiNote2 > 0 Then
Call note_on(0, midiNote2 + Sta, sudu) '使用 note_on 过程播放音符
Else
Call note_off(0, 0) '如果没有音符,停止播放
End If
Sleep 300
Next
End Sub