-
-
' Morse Code Converter
-
' Converts ordinary text into Morse code
-
'
-
-
' Variables that we'll be using
-
'
-
dim i, stringLength, userInput$
-
dim currChar$, tempChar$, currMorseChar$
-
dim alphaData$(37), morseData$(37)
-
-
' Data statements for letters and their Morse representation
-
'
-
data a, ".-", b, "-...", c, "-.-.", d, "-..", e, ".", f, "..-."
-
data g, "--.", h, "....", i, "..", j, ".---", k, "-.-", l, ".-.."
-
data m, "--", n, "-.", o, "---", p, ".--.", q, "--.-", r, ".-."
-
data s, "...", t, "-", u, "..-", v, "...-", w, ".--", x, "-..-"
-
data y, "-.--", z, "--.."
-
-
' Data statements for numbers and their Morse representation. Don't
-
' forget the empty strings at the end, these are important, for
-
' example if the user enters several words separated by a space.
-
'
-
data "0", "-----", "1", ".----", "2", "..---", "3", "...--"
-
data "4", "....-", "5", ".....", "6", "-....", "7", "--..."
-
data "8", "---..", "9", "----."
-
data " ", " "
-
-
' Ask the user to input something
-
'
-
printr "Enter some text please"
-
-
' Store the inputted text
-
'
-
input userInput$
-
-
' No need for upper-case letters
-
'
-
userInput$ = lcase$(userInput$)
-
-
' Get the length of the users text
-
'
-
stringLength = len(userInput$)
-
-
' Clear the screen
-
'
-
Cls
-
-
' Loop through the text
-
'
-
for i = 1 to stringLength
-
-
' Get the next letter from the text
-
'
-
currChar$ = mid$(userInput$, i, 1)
-
-
' Start reading the data statements from the beginning
-
'
-
reset
-
-
' Set tempChar to an empty string. Without this if the user
-
' enters some text which contains repeating letters or numbers
-
' such as rabbit, speed, 999, 911 etc, the code for the repeated
-
' letter/number will be omitted.
-
'
-
tempChar$ = " "
-
-
' Loop through the data statements until we find the letter/number
-
' we're trying to convert
-
'
-
while currChar$ <> tempChar$
-
read alphaData$(i), morseData$(i)
-
tempChar$ = alphaData$(i)
-
wend
-
-
' This is completely unnecessary but it just makes more sense to
-
' print from a variable called currMorseChar than morseData ;-)
-
'
-
currMorseChar$ = morseData$(i)
-
-
' Print the character and its Morse equivalent
-
' separated by an empty string
-
'
-
printr currChar$ " " currMorseChar$
-
-
' Output the text to the screen
-
'
-
drawtext()
-
-
next
-
Comments (0)
You don't have permission to comment on this page.