我希望制作一个虚拟钢琴解码器,它将从这里获取乐谱(http://virtualpiano.net/category/music-sheets/)并将其转换为自动热键的脚本。但我遇到了检测何时同时播放音符的问题, 例 如果我要输入
G ou [pT] [OT]
它应该出现
Send G
Sleep, 100
Sleep, 100
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 100
Send p
Send T
Sleep, 100
Send O
Send T
Sleep, 100
但它出现了
Send G
Sleep, 100
Sleep, 100
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 100
Send p
Sleep, 100
Send T
Sleep, 100
Send O
Sleep, 100
Send T
Sleep, 100
我希望找到“[”和“]”的位置然后更改它之间的文本 我把它说出来是
start = TextBox1.Text
Arraycounter = 0
Do Until -1 = start.IndexOf("[")
Front = start.IndexOf("[")
Back = start.IndexOf("]")
counter = Front
Do Until counter = Back + 1
Middle = Middle & start(counter)
counter += 1
Loop
counter = 0
MsgBox(Front & " - " & Back & " - " & Middle)
start = Replace(start, Middle, SymbleArray(Arraycounter))
Middle = Replace(Middle, "[", "")
Middle = Replace(Middle, "]", "")
Do Until counter = Middle.Length
outp = outp & Replace(Middle(counter), Middle(counter), "SEND " & Middle(counter) & vbNewLine)
counter += 1
Loop
MsgBox(outp)
BraketArray(Arraycounter) = outp
Arraycounter += 1
Middle = ""
outp = ""
Loop
Arraycounter = 0
Do Until Arraycounter = 11
start = Replace(start, SymbleArray(Arraycounter), BraketArray(Arraycounter))
Arraycounter += 1
Loop
TextBox2.Text = start
End Sub
答案 0 :(得分:0)
我尝试简化您的代码。将此代码放在空白控制台项目中。或者,如果您想使用WinForm,请将Console.WriteLine("某些字符串")更改为文本框,例如。 Textbox2.Text ="一些字符串"。
Dim input = "G ou [pT][OT]"
Dim foundBracket As Boolean
For Each c In input
Select Case c
Case " "
Console.WriteLine("Sleep, 200")
Case "["
foundBracket = True
Case "]"
Console.WriteLine("Sleep, 100")
foundBracket = False
Case Else
Console.WriteLine("Send {0}", c)
If Not foundBracket Then Console.WriteLine("Sleep, 100")
End Select
Next
我删除了之间的空格[以匹配预期的结果。我也使用Sleep,200空格。如果您需要处理一些特殊符号,只需将它们添加到case语句中即可。
代码结果:
Send G
Sleep, 100
Sleep, 200
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 200
Send p
Send T
Sleep, 100
Send O
Send T
Sleep, 100