udfStrToMorse (5)
str udfStrToMorse (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse (strString) ; Version 5.
If strString == "" Then Return ""

; Chars = 26 upper alpha chars + 10 numerical chars + 23 upper special chars + one space char. Note: "CH" = "----" ; Not handled by this code.
; Overall 60 chars and their related codes.
strListChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789" : "ÀÅÄÈÉÖÜßÑ.,:;?-_()'=+/@" : " "
strListMorse = ".-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--.." ; 26 Latin codes.
strListMorse = strListMorse : "|" : "-----|.----|..---|...--|....-|.....|-....|--...|---..|----." ; 10 Num codes.
strListMorse = strListMorse : "|" : ".--.-|.--.-|.-.-|.-..-|..-..|---.|..--|...--..|--.--|.-.-.-|--..--|---...|-.-.-.|..--..|-....-|..--.-|-.--.|-.--.-|.----.|-...-|.-.-.|-..-.|.--.-." ; 23 Special codes.
strListMorse = strListMorse : "|" : " " ; 1 Space code.

objDict = CreateObject ("Scripting.Dictionary")
objDict.CompareMode = 0 ; BinaryCompare, i. e. "That" != "that"

For intI = 1 To 60
   objDict.Add(StrSub(strListChars, intI, 1), ItemExtract (intI, strListMorse, "|"))
Next

strString = StrUpper (StrClean (strString, strListChars, "", @FALSE, 2)) ; Remove all other unknown chars.
intLast = StrLen (strString)
strMorse = ""
For intI = 1 To intLast
   strMorse = strMorse : objDict.Item(StrSub(strString, intI, 1))
Next

objDict.RemoveAll
Drop (objDict)

Return strMorse
;..........................................................................................................................................
; This UDF "udfStrToMorse" converts a given string into it's equivalent Morse code.
;
; strCharsLatin = "abcdefghijklmnopqrstuvwxyz" ; 26 upper alpha chars.
; strCharsNum = "0123456789" ; 10 numerical chars.
; strCharsSpecial = "ÀÅÄÈÉÖÜßÑ.,:;?-_()'=+/@" ; 23 special chars.
; Note: "CH" = "----" ; Not handled by this code.
;
; Detlev Dalitz.20101223.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strString = "SOS"
strMorse = udfStrToMorse (strString) ; strMorse = "...---..."
strMsgTitle = strString
strMsgText = strMorse
Message (strMsgTitle, strMsgText)

strString = "- (  [<{Hello}>] World!  ) ? ."
strMorse = udfStrToMorse (strString) ; strMorse = "-....- -.--.  ......-...-..--- .-----.-..-..-..  -.--.- ..--.. .-.-.-"
strMsgTitle = strString
strMsgText = strMorse
Message (strMsgTitle, strMsgText)

lExit