Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Gambas class file
- Private morseTable As Collection
- Public Sub Form_Open()
- Me.center
- Music.Load("beep-01a.wav")
- setupMorse()
- End
- Public Sub setupMorse()
- morseTable = New Collection
- morseTable.Add(".-", "a")
- morseTable.Add("-...", "b")
- morseTable.Add("-.-.", "c")
- morseTable.Add("-..", "d")
- morseTable.Add(".", "e")
- morseTable.Add("..-.", "f")
- morseTable.Add("--.", "g")
- morseTable.Add("....", "h")
- morseTable.Add("..", "i")
- morseTable.Add(".---", "j")
- morseTable.Add("-.-", "k")
- morseTable.Add(".-..", "l")
- morseTable.Add("--", "m")
- morseTable.Add("-.", "n")
- morseTable.Add("---", "o")
- morseTable.Add(".--.", "p")
- morseTable.Add("--.-", "q")
- morseTable.Add(".-.", "r")
- morseTable.Add("...", "s")
- morseTable.Add("-", "t")
- morseTable.Add("..-", "u")
- morseTable.Add("...-", "v")
- morseTable.Add(".--", "w")
- morseTable.Add("-..-", "x")
- morseTable.Add("-.--", "y")
- morseTable.Add("--..", "z")
- morseTable.Add("-----", "0")
- morseTable.Add(".----", "1")
- morseTable.Add("..---", "2")
- morseTable.Add("...--", "3")
- morseTable.Add("....-", "4")
- morseTable.Add(".....", "5")
- morseTable.Add("-....", "6")
- morseTable.Add("--...", "7")
- morseTable.Add("---..", "8")
- morseTable.Add("----.", "9")
- morseTable.Add(".-.-.-", ".")
- morseTable.Add("--..--", ",")
- morseTable.Add("..--..", "?")
- morseTable.Add(".----.", "'")
- morseTable.Add("-.-.--", "!")
- morseTable.Add("-..-.", "/")
- morseTable.Add("-.--.", "(")
- morseTable.Add("-.--.-", ")")
- morseTable.Add(".-...", "&")
- morseTable.Add("---...", ":")
- morseTable.Add("-.-.-.", ";")
- morseTable.Add("-...-", "=")
- morseTable.Add(".-.-.", "+")
- morseTable.Add("-....-", "-")
- morseTable.Add("..--.-", "_")
- morseTable.Add(".-..-.", "\"")
- morseTable.Add("...-..-", "$")
- morseTable.Add(".--.-.", "@")
- End
- Public Sub Button1_Click()
- Dim idx As Integer
- Dim aChar As String
- For idx = 1 To Len(TextBox1.text)
- aChar = Mid$(TextBox1.text, idx, 1)
- If aChar = " " Then
- Print "Break between words"
- ' Pause between words (perhaps do something to eliminate multiple spaces?)
- Wait 0.7
- Continue
- Endif
- playChar(aChar)
- Next
- End Sub
- Public Sub playChar(aChar As String)
- Dim charAsMorse As String
- Dim idx As Integer
- charAsMorse = morseTable[Lower$(aChar)]
- Print "Playing: " & charAsMorse
- For idx = 1 To Len(charAsMorse)
- TextLabelLetra.text = "Letra: \"" & achar & "\" código: \"" & charAsMorse & "\""
- If Mid$(charAsMorse, idx, 1) = "." Then
- playDot()
- Else
- playDash()
- Endif
- ' Pause between individual dots/dashes of a single character
- Wait 0.2
- Next
- ' Pause between characters of a word
- Wait 0.5
- End
- Public Sub playDot()
- playTone(0.1)
- End
- Public Sub playDash()
- playTone(0.4)
- End
- Public Sub playTone(duration As Float)
- Music.Play()
- Wait duration
- Music.Stop()
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement