Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Imports System.Text
- ''' <summary>
- ''' BeepBeepMorse is a simple class that will help you convert strings to morse and vice versa.
- ''' It supports Alphanumericals and some special chars.
- ''' Coded By SubGenius @Hackforums.net
- '''
- ''' 16/1/14
- ''' Now you can play the morse codes.
- ''' Currently using the console.beep sub.
- '''
- ''' *** SOS ***
- ''' To add new characters to the "library" you must add the normal character and the corresponding new string in the same location.
- ''' For example. the period character in "Alpahabet" has the coresponding morse character in the same position in "Morse".
- ''' or the "Space"(" ") character corresponds to the backslash, many online Morse compilers use backslash to identify the space char.
- ''' *** SOS ***
- ''' </summary>
- ''' <remarks></remarks>
- Public Class MorseClass
- Dim Alphabet As String() = {" ", ".", ",", ":", "?", "'", "/", "@", "()", "=", "-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
- Dim Morse As String() = {"/", ".-.-.-", "--..--", "---...", "..--..", ".----.", "-..-.", ".--.-.", "-.--.-", "-...-", "-....-", "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}
- Private _PlayToneLength As Integer = 100
- Property PlayToneLength As Integer
- Set(value As Integer)
- _PlayToneLength = value
- End Set
- Get
- Return _PlayToneLength
- End Get
- End Property
- Private _Seperator As Char
- Property Seperator As Char
- Set(value As Char)
- _Seperator = value
- End Set
- Get
- Return _Seperator
- End Get
- End Property
- ''' <summary>
- ''' Creates a new Morse Class
- ''' </summary>
- ''' <param name="SeperatorChar">This char will seperate the different morse strings.</param>
- ''' <remarks></remarks>
- Sub New(Optional ByVal SeperatorChar As Char = " ")
- _Seperator = SeperatorChar
- End Sub
- ''' <summary>
- ''' Converts an normal alphabet character to morse character.
- ''' </summary>
- ''' <param name="character">The character you want to convert to morse.</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Function GetMorseChar(ByVal character As Char) As String
- For i As Integer = 0 To (Alphabet.Length - 1)
- If Alphabet(i) = character Then
- Return Morse(i) : Exit For
- End If
- Next
- Return Nothing
- End Function
- ''' <summary>
- ''' Converts an morse character to normal alphabet character.
- ''' </summary>
- ''' <param name="text">The morse character you want to convert to normal alphabet char.</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Function GetAlphabetChar(ByVal text As String) As Char
- For i As Integer = 0 To (Morse.Length - 1)
- If Morse(i) = text Then
- Return CChar(Alphabet(i)) : Exit For
- End If
- Next
- Return Nothing
- End Function
- ''' <summary>
- ''' Converts the selected text to morse string.
- ''' </summary>
- ''' <param name="NormalText">The morse string you want to convert.</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Function CompileText(ByVal NormalText As String) As String
- Dim Builder As New StringBuilder
- For Each character As Char In NormalText
- Builder.Append(GetMorseChar(character) & Seperator)
- Next
- Return Builder.ToString
- End Function
- ''' <summary>
- ''' Converts the selected morse text to normal string.
- ''' </summary>
- ''' <param name="MorseText">The morse string you want to convert.</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Function CompileMorse(ByVal MorseText) As String
- Dim CharsSplitted As String() = MorseText.Split(Seperator)
- Dim Builder As New StringBuilder
- For Each character As String In CharsSplitted
- Builder.Append(GetAlphabetChar(character))
- Next
- Return Builder.ToString
- End Function
- Sub PlayMorse(ByVal MorseString As String)
- For Each character As Char In MorseString
- Select Case character
- Case CChar(".")
- Console.Beep(700, _PlayToneLength)
- Case CChar("-")
- Console.Beep(700, 4 * _PlayToneLength)
- Case Seperator
- Threading.Thread.Sleep(5 * _PlayToneLength)
- Case Else
- Threading.Thread.Sleep(3 * _PlayToneLength)
- End Select
- Next
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment