问题描述
我需要帮助制作 VB Excel 宏,该宏将从 InputBox 获取输入并将其从英语转换为 Morse,反之亦然,然后在 MessageBox 中显示结果。我被卡住了,我不知道我怎么能做到。提前感谢您的帮助
解决方法
请参阅以下内容(仅供参考 - 您可能需要将代码转换为 VBA,但我相信您可以做到)
If txtInput.Text = "a" Then
lblStatus.Caption = ".-"
End If
If txtInput.Text = "b" Then
lblStatus.Caption = "-..."
End If
If txtInput.Text = "c" Then
lblStatus.Caption = "-.-."
End If
If txtInput.Text = "d" Then
lblStatus.Caption = "-.."
End If
If txtInput.Text = "e" Then
lblStatus.Caption = "."
End If
If txtInput.Text = "f" Then
lblStatus.Caption = "..-."
End If
If txtInput.Text = "g" Then
lblStatus.Caption = "--."
End If
If txtInput.Text = "h" Then
lblStatus.Caption = "...."
End If
If txtInput.Text = "i" Then
lblStatus.Caption = ".."
End If
If txtInput.Text = "j" Then
lblStatus.Caption = ".---"
End If
If txtInput.Text = "k" Then
lblStatus.Caption = "-.-"
End If
If txtInput.Text = "l" Then
lblStatus.Caption = ".-.."
End If
If txtInput.Text = "m" Then
lblStatus.Caption = "--"
End If
If txtInput.Text = "n" Then
lblStatus.Caption = "-."
End If
If txtInput.Text = "o" Then
lblStatus.Caption = "---"
End If
If txtInput.Text = "p" Then
lblStatus.Caption = ".--."
End If
If txtInput.Text = "q" Then
lblStatus.Caption = "--.-"
End If
If txtInput.Text = "r" Then
lblStatus.Caption = ".-."
End If
If txtInput.Text = "s" Then
lblStatus.Caption = "..."
End If
If txtInput.Text = "t" Then
lblStatus.Caption = "-"
End If
If txtInput.Text = "u" Then
lblStatus.Caption = "..-"
End If
If txtInput.Text = "v" Then
lblStatus.Caption = "...-"
End If
If txtInput.Text = "w" Then
lblStatus.Caption = ".--"
End If
If txtInput.Text = "x" Then
lblStatus.Caption = "-..-"
End If
If txtInput.Text = "y" Then
lblStatus.Caption = "-.--"
End If
If txtInput.Text = "z" Then
lblStatus.Caption = "--.."
End If
If txtInput.Text = "0" Then
lblStatus.Caption = "-----"
End If
If txtInput.Text = "1" Then
lblStatus.Caption = ".----"
End If
If txtInput.Text = "2" Then
lblStatus.Caption = "..---"
End If
If txtInput.Text = "3" Then
lblStatus.Caption = "...--"
End If
If txtInput.Text = "4" Then
lblStatus.Caption = "....-"
End If
If txtInput.Text = "5" Then
lblStatus.Caption = "....."
End If
If txtInput.Text = "6" Then
lblStatus.Caption = "-...."
End If
If txtInput.Text = "7" Then
lblStatus.Caption = "--..."
End If
If txtInput.Text = "8" Then
lblStatus.Caption = "---.."
End If
If txtInput.Text = "9" Then
lblStatus.Caption = "----."
End If
,
英语到摩尔斯电码
- 尽管默认情况下这几乎是使用
Dictionary object
完成的,但我仍然坚持使用数组作为一个有趣的替代方案。
代码
--------------------------------------------------------------------------------
\s* whitespace (\n,\r,\t,\f,and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\[ '['
--------------------------------------------------------------------------------
[^\][]* any character except: '\]','[' (0 or more
times (matching the most amount possible))
--------------------------------------------------------------------------------
] ']'
--------------------------------------------------------------------------------
\s* whitespace (\n,and " ") (0 or
more times (matching the most amount
possible))