Profiling converting string to morse code
;==========================================================================================================================================
; Convert a string into it's equivalent Morse code.
;
; Profiling Performance Contest.
;
;   udfStrToMorse - Version 1, Detlev Dalitz.20090703.20101223.
;   udfStrToMorse - Version 2, Detlev Dalitz.20090703.20101223.
;   udfStrToMorse - Version 3, Detlev Dalitz.20090703.20101223.
;   udfStrToMorse - Version 4, Detlev Dalitz.20101223.
;   udfStrToMorse - Version 5, Detlev Dalitz.20101223.
;
;------------------------------------------------------------------------------------------------------------------------------------------
; (c)Detlev Dalitz.20101223.
;==========================================================================================================================================


; How many different test cases?
intContestCaseMax = 3

; How many loops to run?
intContestLoopMax = 100

; What group of contestants to examine?
intContestantMin = 2
intContestantMax = 5

; Previewing of test case results?
blnPreviewResults = @TRUE
;blnPreviewResults = @FALSE


GoSub DEFINE_FUNCTIONS

; Run the contest once and display the results for verifying.
; Then press CANCEL to abort or OK to run complete contest.
If blnPreviewResults
   For intContestCase = 1 To intContestCaseMax
      udsPrepareTestCase (intContestCase)
      udsPrepareCounters ()
      For intContestant = intContestantMin To intContestantMax
         udsRunContestant (intContestant)
      Next
      If @CANCEL == udfArrayDumpToItemList (arrContestResults, intContestantMin, intContestantMax, @LF) Then Goto CANCEL
   Next
EndIf

; Run complete contest.
WinShow ("")
strContestResult = ""
For intContestCase = 1 To intContestCaseMax
   udsPrepareTestCase (intContestCase)
   udsPrepareCounters ()
   For intContestLoop = 1 To intContestLoopMax
      For intContestant = intContestantMin To intContestantMax
         WinTitle ("", "Profiling|Case=" : intContestCaseMax : "." : intContestCase : "|Contestant=" : intContestantMax : "." : intContestant : "|Loop=" : intContestLoopMax : "." : intContestLoop)
         udsRunContestant (intContestant)
      Next
   Next
   strContestResult = strContestResult : @LF : udsResultPerTestCase ()
Next
strContestResult = strContestResult : @LF : strPre : StrFill ("-", intLenSum)
strContestResult = StrSub (strContestResult, 2, -1)

Message (strMsgTitle, strContestResult)
ClipPut (StrReplace (strContestResult, @LF, @CRLF))

:CANCEL
Exit
;==========================================================================================================================================



;==========================================================================================================================================
:DEFINE_FUNCTIONS
;==========================================================================================================================================

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsPrepareTestCase (intContestCase)
Switch intContestCase
Case 1
   strString = "SOS"
   ; strResult = "...---..."
   Break
Case 2
   strString = "- (  [<{Hello}>] World! ß=?-_) ? ."
   ; strResult = "-....- -.--.  ......-...-..--- .-----.-..-..-.. ...--..-...-..--..-....-..--.--.--.- ..--.."
   Break
Case 3
   strString = "This is a profiling contest for 5 different algorithms."
   ; strResult = "-......... ..... .- .--..-.---..-....-....-.--. -.-.----.-....- ..-.---.-. ..... -......-...-...-..-.- .-.-..--.---.-...-....--....-.-.-"
   Break
EndSwitch
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsRunContestant (intContestant)
Exclusive (@ON)
Switch intContestant
Case 1
   arrContestants[intContestant] = "udfStrToMorse_1"
   intStart = GetTickCount ()
   arrContestResults[intContestant] = udfStrToMorse_1 (strString)
   intStop = GetTickCount ()
   arrContestTicks[intContestant] = arrContestTicks[intContestant] + intStop - intStart
   Break

Case 2
   arrContestants[intContestant] = "udfStrToMorse_2"
   intStart = GetTickCount ()
   arrContestResults[intContestant] = udfStrToMorse_2 (strString)
   intStop = GetTickCount ()
   arrContestTicks[intContestant] = arrContestTicks[intContestant] + intStop - intStart
   Break

Case 3
   arrContestants[intContestant] = "udfStrToMorse_3"
   intStart = GetTickCount ()
   arrContestResults[intContestant] = udfStrToMorse_3 (strString)
   intStop = GetTickCount ()
   arrContestTicks[intContestant] = arrContestTicks[intContestant] + intStop - intStart
   Break

Case 4
   arrContestants[intContestant] = "udfStrToMorse_4"
   intStart = GetTickCount ()
   arrContestResults[intContestant] = udfStrToMorse_4 (strString)
   intStop = GetTickCount ()
   arrContestTicks[intContestant] = arrContestTicks[intContestant] + intStop - intStart
   Break

Case 5
   arrContestants[intContestant] = "udfStrToMorse_5"
   intStart = GetTickCount ()
   arrContestResults[intContestant] = udfStrToMorse_5 (strString)
   intStop = GetTickCount ()
   arrContestTicks[intContestant] = arrContestTicks[intContestant] + intStop - intStart
   Break
EndSwitch
Exclusive (@OFF)
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse_1 (strString) ; Version 1.
If strString == "" Then Return ""
strString = StrUpper (strString)
strMorse = ""
intLen = StrLen (strString)
For intI = 1 To intLen
   Switch Char2Num (StrSub (strString, intI, 1))
   Case 065 ; "A"
      strMorse = strMorse : ".-"
      Break
   Case 066 ; "B"
      strMorse = strMorse : "-..."
      Break
   Case 067 ; "C"
      strMorse = strMorse : "-.-."
      Break
   Case 068 ; "D"
      strMorse = strMorse : "-.."
      Break
   Case 069 ; "E"
      strMorse = strMorse : "."
      Break
   Case 070 ; "F"
      strMorse = strMorse : "..-."
      Break
   Case 071 ; "G"
      strMorse = strMorse : "--."
      Break
   Case 072 ; "H"
      strMorse = strMorse : "...."
      Break
   Case 073 ; "I"
      strMorse = strMorse : ".."
      Break
   Case 074 ; "J"
      strMorse = strMorse : ".---"
      Break
   Case 075 ; "K"
      strMorse = strMorse : "-.-"
      Break
   Case 076 ; "L"
      strMorse = strMorse : ".-.."
      Break
   Case 077 ; "M"
      strMorse = strMorse : "--"
      Break
   Case 078 ; "N"
      strMorse = strMorse : "-."
      Break
   Case 079 ; "O"
      strMorse = strMorse : "---"
      Break
   Case 080 ; "P"
      strMorse = strMorse : ".--."
      Break
   Case 081 ; "Q"
      strMorse = strMorse : "--.-"
      Break
   Case 082 ; "R"
      strMorse = strMorse : ".-."
      Break
   Case 083 ; "S"
      strMorse = strMorse : "..."
      Break
   Case 084 ; "T"
      strMorse = strMorse : "-"
      Break
   Case 085 ; "U"
      strMorse = strMorse : "..-"
      Break
   Case 086 ; "V"
      strMorse = strMorse : "...-"
      Break
   Case 087 ; "W"
      strMorse = strMorse : ".--"
      Break
   Case 088 ; "X"
      strMorse = strMorse : "-..-"
      Break
   Case 089 ; "Y"
      strMorse = strMorse : "-.--"
      Break
   Case 090 ; "Z"
      strMorse = strMorse : "--.."
      Break
   Case 048 ; "0"
      strMorse = strMorse : "-----"
      Break
   Case 049 ; "1"
      strMorse = strMorse : ".----"
      Break
   Case 050 ; "2"
      strMorse = strMorse : "..---"
      Break
   Case 051 ; "3"
      strMorse = strMorse : "...--"
      Break
   Case 052 ; "4"
      strMorse = strMorse : "....-"
      Break
   Case 053 ; "5"
      strMorse = strMorse : "....."
      Break
   Case 054 ; "6"
      strMorse = strMorse : "-...."
      Break
   Case 055 ; "7"
      strMorse = strMorse : "--..."
      Break
   Case 056 ; "8"
      strMorse = strMorse : "---.."
      Break
   Case 057 ; "9"
      strMorse = strMorse : "----."
      Break
   Case 192 ; "À"
      strMorse = strMorse : ".--.-"
      Break
   Case 197 ; "Å"
      strMorse = strMorse : ".--.-"
      Break
   Case 196 ; "Ä"
      strMorse = strMorse : ".-.-"
      Break
   Case 200 ; "È"
      strMorse = strMorse : ".-..-"
      Break
   Case 201 ; "É"
      strMorse = strMorse : "..-.."
      Break
   Case 214 ; "Ö"
      strMorse = strMorse : "---."
      Break
   Case 220 ; "Ü"
      strMorse = strMorse : "..--"
      Break
   Case 223 ; "ß"
      strMorse = strMorse : "...--.."
      Break
   Case 209 ; "Ñ"
      strMorse = strMorse : "--.--"
      Break
   Case 046 ; "."
      strMorse = strMorse : ".-.-.-"
      Break
   Case 044 ; ","
      strMorse = strMorse : "--..--"
      Break
   Case 058 ; ":"
      strMorse = strMorse : "---..."
      Break
   Case 059 ; ";"
      strMorse = strMorse : "-.-.-."
      Break
   Case 063 ; "?"
      strMorse = strMorse : "..--.."
      Break
   Case 045 ; "-"
      strMorse = strMorse : "-....-"
      Break
   Case 095 ; "_"
      strMorse = strMorse : "..--.-"
      Break
   Case 040 ; "("
      strMorse = strMorse : "-.--."
      Break
   Case 041 ; ")"
      strMorse = strMorse : "-.--.-"
      Break
   Case 039 ; "'"
      strMorse = strMorse : ".----."
      Break
   Case 061 ; "="
      strMorse = strMorse : "-...-"
      Break
   Case 043 ; "+"
      strMorse = strMorse : ".-.-."
      Break
   Case 047 ; "/"
      strMorse = strMorse : "-..-."
      Break
   Case 064 ; "@"
      strMorse = strMorse : ".--.-."
      Break
   Case 032 ; " "
      strMorse = strMorse : " "
      Break
   EndSwitch
Next
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.20090703.20101223.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse_2 (strString) ; Version 2.
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.
strChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789" : "ÀÅÄÈÉÖÜßÑ.,:;?-_()'=+/@"
strDelim = "|"
strMorseLatin = ".-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--.." ; 26 codes.
strMorseNum = "-----|.----|..---|...--|....-|.....|-....|--...|---..|----." ; 10 codes.
strMorseSpecial = ".--.-|.--.-|.-.-|.-..-|..-..|---.|..--|...--..|--.--|.-.-.-|--..--|---...|-.-.-.|..--..|-....-|..--.-|-.--.|-.--.-|.----.|-...-|.-.-.|-..-.|.--.-." ; 23 codes.
arrMorse = Arrayize (strMorseLatin : strDelim : strMorseNum : strDelim : strMorseSpecial, strDelim) ; 59 codes.
strSpace = " "
strPoint = "."
strHyphen = "-"
strSurrogateSpace = Num2Char (1)
strSurrogatePoint = Num2Char (2)
strSurrogateHyphen = Num2Char (3)
strRemoveChars = strSurrogateSpace : strSurrogatePoint : strSurrogateHyphen : strPoint : strHyphen
strSaveChars = strSurrogateSpace : strSurrogatePoint : strSurrogateHyphen : strChars
strString = StrReplace (strString, strSpace, strSurrogateSpace)   ; Mask all spaces.
strString = StrReplace (strString, strPoint, strSurrogatePoint)   ; Mask all points.
strString = StrReplace (strString, strHyphen, strSurrogateHyphen) ; Mask all hyphens.
strString = StrClean (strString, strSaveChars, "", @FALSE, 2) ; Remove all other unknown chars.
strString = StrUpper (strString)
While @TRUE
   strTemp = StrClean (strString, strRemoveChars, "", @TRUE, 1) ; Remove all Morse chars, create remaining chars list.
   If strTemp == "" Then Break
   strChar = StrSub (strTemp, 1, 1) ; Get next char from remaining chars list.
   strMorse = arrMorse [StrIndex (strChars, strChar, 1, @FWDSCAN) - 1] ; Lookup Morse code.
   strString = StrReplace (strString, strChar, strMorse) ; Replace all same chars with same Morse code.
EndWhile
strString = StrReplace (strString, strSurrogateHyphen, arrMorse [StrIndex (strChars, strHyphen, 1, @FWDSCAN) - 1]) ; Demask and encode all hyphens-
strString = StrReplace (strString, strSurrogatePoint, arrMorse [StrIndex (strChars, strPoint, 1, @FWDSCAN) - 1]) ; Demask and encode all points-
strString = StrReplace (strString, strSurrogateSpace, strSpace) ; Demask all spaces-
Return strString
;..........................................................................................................................................
; 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.20090703.20101223.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse_3 (strString) ; Version 3.
If strString == "" Then Return ""

strCharsLatin = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; 26 upper alpha chars.
strCharsNum = "0123456789" ; 10 numerical chars.
strCharsSpecial = "ÀÅÄÈÉÖÜßÑ.,:;?-_()'=+/@" ; 23 upper special chars. ; Note: CH = "----" ; not handled by this code.
strSpace = " "
strChars = strCharsLatin : strCharsNum : strCharsSpecial : strSpace
Drop (strCharsLatin, strCharsNum, strCharsSpecial)

strDelim = "|"
strMorseLatin = ".-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--.." ; 26 codes.
strMorseNum = "-----|.----|..---|...--|....-|.....|-....|--...|---..|----." ; 10 codes.
strMorseSpecial = ".--.-|.--.-|.-.-|.-..-|..-..|---.|..--|...--..|--.--|.-.-.-|--..--|---...|-.-.-.|..--..|-....-|..--.-|-.--.|-.--.-|.----.|-...-|.-.-.|-..-.|.--.-." ; 23 codes.
arrMorse = Arrayize (strMorseLatin : strDelim : strMorseNum : strDelim : strMorseSpecial : strDelim : strSpace, strDelim) ; 60 codes (59 codes plus one space).
DropWild ("strMorse*")
Drop (strDelim, strSpace)

strSplit = ""
For intI = 1 To 255
   strDelimiter = Num2Char (intI)
   If !StrIndex (strChars, strDelimiter, 1, @FWDSCAN)
      objRegExp = ObjectCreate ("VBScript.RegExp")
      objRegExp.IgnoreCase = @FALSE
      objRegExp.MultiLine = @FALSE
      objRegExp.Global = @TRUE
      objRegExp.Pattern = ""
      strSplit = objRegExp.Replace(strChars, strDelimiter)
      objRegExp.Pattern = "^" : strDelimiter : "|" : strDelimiter : "$"
      arrChars = Arrayize (objRegExp.Replace(strSplit, ""), strDelimiter)
      DropWild ("obj*")
      Break
   EndIf
Next
Terminate (strSplit == "", "Terminated.", "Cannot arrayize charset.")
Drop (strSplit)

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

intArrayElements = ArrInfo (arrChars, 1)
intMax = intArrayElements - 1
For intI = 0 To intMax
   objDict.Add(arrChars [intI], arrMorse[intI])
Next
Drop (arrChars)

strString = StrUpper (StrClean (strString, strChars, "", @FALSE, 2)) ; Remove all other unknown chars.
strMorse = ""
intLen = StrLen (strString)
For intI = 1 To intLen
   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.20090703
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse_4 (strString) ; Version 4.
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.
strChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "0123456789" : "ÀÅÄÈÉÖÜßÑ.,:;?-_()'=+/@" : " "
strString = StrUpper (StrClean (strString, strChars, "", @FALSE, 2)) ; Remove all other unknown chars.
arrChars = ArrayFromStr (strChars)

strMorseLatin = ".-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--.." ; 26 codes.
strMorseNum = "-----|.----|..---|...--|....-|.....|-....|--...|---..|----." ; 10 codes.
strMorseSpecial = ".--.-|.--.-|.-.-|.-..-|..-..|---.|..--|...--..|--.--|.-.-.-|--..--|---...|-.-.-.|..--..|-....-|..--.-|-.--.|-.--.-|.----.|-...-|.-.-.|-..-.|.--.-." ; 23 codes.
arrMorse = Arrayize (strMorseLatin : "|" : strMorseNum : "|" : strMorseSpecial : "|" : " ", "|") ; 60 codes (59 codes plus one space).

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

intLast = ArrInfo (arrChars, 1) - 1
For intI = 0 To intLast
   objDict.Add(arrChars [intI], arrMorse[intI])
Next

strMorse = ""
intLast = StrLen (strString)
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 = "ÀÅÄÈÉÖÜßÑ.,:;?-()'=+/@" ; 22 special chars.
; Note: "CH" = "----" ; Not handled by this code.
;
; Detlev Dalitz.20090703.20101223.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrToMorse_5 (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
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayDumpToItemList (arrArray, intFirst, intLast, strDelimiter)
If !ArrInfo (arrArray, -1) Then Return "*ARRAY_IS_INVALID*" ; No Array, return invalid itemlist, i. e. empty string "".
If ArrInfo (arrArray, 0) != 1 Then Return "*ARRAY_IS_NOT_DIM_1*" ; Array is not a dim-1 array, return invalid itemlist, i. e. empty string "".
intElements = ArrInfo (arrArray, 1)
If intElements == 0 Then Return "*ARRAY_HAS_NO_ELEMENTS*" ; Array has no element.
intFirst = Min (Max (intFirst, 0), intElements - 1)
intLast = Min (Max (intLast, 0), intElements - 1)
strItemList = ""
intFixSize = StrLen (intLast)
For intI = intFirst To intLast
   If !!VarType (arrArray [intI])
      If arrArray [intI] == ""
         strItemList = ItemInsert (StrFixLeft (intI, "0", intFixSize) : "|" : "*ARRAY_ELEMENT_IS_EMPTY_STRING*", -1, strItemList, strDelimiter)
      Else
         arrArray [intI] = StrReplace (StrReplace (StrReplace (StrReplace (arrArray [intI], @CRLF, "@CRLF"), @CR, "@CR"), @LF, "@LF"), @TAB, "@TAB") ; Make WB style.
         arrArray [intI] = StrSub (arrArray [intI], 1, 200) ; Special truncation just for the small buffer of AskItemList.
         strItemList = ItemInsert (StrFixLeft (intI, "0", intFixSize) : "|" : arrArray [intI], -1, strItemList, strDelimiter)
      EndIf
   Else
      strItemList = ItemInsert (StrFixLeft (intI, "0", intFixSize) : "|" : "*ARRAY_ELEMENT_IS_UNDEFINED*", -1, strItemList, strDelimiter)
   EndIf
Next
IntControl (28, 1, 0, 0, 0)
IntControl (63, 050, 200, 950, 800)
Return AskItemlist ("Profiling|Preview Contestant Result", strItemList, strDelimiter, @UNSORTED, @SINGLE) ; This returns a Unicode string of VarType=128.
:CANCEL
Return @CANCEL
;..........................................................................................................................................
; This UDF "udfArrayDumpToItemList" reads a dim-1 array and returns an itemlist of all array cell items within an AskItemList dialog..
;
; Return values:
; "*ARRAY_IS_INVALID*"              ... Invalid array resp. this is no array.
; "*ARRAY_IS_NOT_DIM_1*"            ... Array is not a dim-1 array.
; "*ARRAY_HAS_NO_ELEMENTS*"         ... Array has no element.
; "*ARRAY_ELEMENT_IS_EMPTY_STRING*" ... Array element has vartype STRING but is empty.
; "*ARRAY_ELEMENT_IS UNDEFINED*"    ... Array element has undefined VarType.
; value                             ... Current value of the array element.
;
; Example: strItemList = udfArrayDumpToItemList (arrArray, 0, 19, @TAB)
;
; Detlev Dalitz.20090515.20100122.20101222.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsPrepareCounters ()
arrContestants = ArrDimension (1 + intContestantMax)    ; Array index 0 will not be used.
arrContestResults = ArrDimension (1 + intContestantMax) ; Array index 0 will not be used.
arrContestTicks = ArrDimension (1 + intContestantMax)   ; Array index 0 will be used for the sum.
arrContestPct = ArrDimension (1 + intContestantMax)     ; Array index 0 will not be used.
ArrInitialize (arrContestants, "")
ArrInitialize (arrContestResults, "")
ArrInitialize (arrContestTicks, 0)
ArrInitialize (arrContestPct, 0.0)
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsResultPerTestCase ()
Decimals (1)
For intContestant = intContestantMin To intContestantMax
   arrContestTicks[0] = arrContestTicks[0] + arrContestTicks[intContestant]
Next
intContestTicksMin = arrContestTicks[0]
For intContestant = intContestantMin To intContestantMax
   intContestTicksMin = Min (intContestTicksMin, arrContestTicks[intContestant])
Next
If arrContestTicks[0] < 1 Then arrContestTicks[0] = 1 ; To prevent dividing by zero.
For intContestant = intContestantMin To intContestantMax
   arrContestPct[intContestant] = 100.0 * arrContestTicks[intContestant] / arrContestTicks[0]
Next

; Format output.
strMsgTitle = "Performance Contest Result"
strTest = "Test"
strTicks = "Ticks"
strPct = "Pct"
strContestant = "Contestant"
strSep = "  "
strPre = "; "
strWinner = "<== The Winner"
intLenTest = Max (StrLen (strTest), StrLen (intContestantMax))
intLenTicks = StrLen (strTicks)
intLenPct = StrLen (strPct)
intLenContestant = StrLen (strContestant)
intLenSep = StrLen (strSep)
intLenWinner = StrLen (strWinner)
For intContestant = intContestantMin To intContestantMax
   intLenTicks = Max (intLenTicks, StrLen (arrContestTicks[intContestant]))
   intLenPct = Max (intLenPct, StrLen (arrContestPct[intContestant]))
   intLenContestant = Max (intLenContestant, StrLen (arrContestants[intContestant]))
Next
intLenSum = intLenTest + intLenTicks + intLenPct + intLenContestant + intLenWinner + 4 * intLenSep
strTest = StrFixLeft (strTest, " ", intLenTest)
strTicks = StrFixLeft (strTicks, " ", intLenTicks)
strPct = StrFixLeft (strPct, " ", intLenPct)
strResult = strPre : StrFill ("-", intLenSum) : @LF : strPre : strMsgTitle
strResult = strResult : @LF : strPre : "Contest Case = " : intContestCase
strResult = strResult : @LF : strPre : "Iterations = " : intContestLoopMax
strResult = strResult : @LF : strPre : strTest : strSep : strTicks : strSep : strPct : strSep : strContestant
For intContestant = intContestantMin To intContestantMax
   strTest = StrFixLeft (intContestant, " ", intLenTest)
   strTicks = StrFixLeft (arrContestTicks[intContestant], " ", intLenTicks)
   strPct = StrFixLeft (arrContestPct[intContestant], " ", intLenPct)
   strContestant = StrFix (arrContestants[intContestant], " ", intLenContestant)
   If arrContestTicks[intContestant] == intContestTicksMin Then strContestant = strContestant : strSep : strWinner
   strResult = strResult : @LF : strPre : strTest : strSep : strTicks : strSep : strPct : strSep : strContestant
Next
Return strResult : @LF : strPre : "DateTime = " : TimeYmdHms ()
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------

;==========================================================================================================================================
Return ; from GoSub DEFINE_FUNCTIONS
;==========================================================================================================================================

; --------------------------------------------------
; Performance Contest Result
; Contest Case = 1
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    1   1763  24.2  udfStrToMorse_1
;    2    403   5.5  udfStrToMorse_2  <== The Winner
;    3   1835  25.2  udfStrToMorse_3
;    4   1513  20.8  udfStrToMorse_4
;    5   1770  24.3  udfStrToMorse_5
; DateTime = 2010:12:23:22:04:43
; --------------------------------------------------
; Performance Contest Result
; Contest Case = 2
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    1  15000  64.0  udfStrToMorse_1
;    2   1390   5.9  udfStrToMorse_2  <== The Winner
;    3   2471  10.5  udfStrToMorse_3
;    4   2156   9.2  udfStrToMorse_4
;    5   2421  10.3  udfStrToMorse_5
; DateTime = 2010:12:23:22:05:07
; --------------------------------------------------
; Performance Contest Result
; Contest Case = 3
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    1  23865  68.6  udfStrToMorse_1
;    2   1860   5.3  udfStrToMorse_2  <== The Winner
;    3   3109   8.9  udfStrToMorse_3
;    4   2875   8.3  udfStrToMorse_4
;    5   3059   8.8  udfStrToMorse_5
; DateTime = 2010:12:23:22:05:43
; --------------------------------------------------

; --------------------------------------------------
; Performance Contest Result
; Contest Case = 1
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    2    515   9.0  udfStrToMorse_2  <== The Winner
;    3   1857  32.3  udfStrToMorse_3
;    4   1469  25.6  udfStrToMorse_4
;    5   1908  33.2  udfStrToMorse_5
; DateTime = 2010:12:23:22:07:45
; --------------------------------------------------
; Performance Contest Result
; Contest Case = 2
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    2   1404  16.5  udfStrToMorse_2  <== The Winner
;    3   2551  29.9  udfStrToMorse_3
;    4   2172  25.5  udfStrToMorse_4
;    5   2407  28.2  udfStrToMorse_5
; DateTime = 2010:12:23:22:07:55
; --------------------------------------------------
; Performance Contest Result
; Contest Case = 3
; Iterations = 100
; Test  Ticks   Pct  Contestant
;    2   1752  16.5  udfStrToMorse_2  <== The Winner
;    3   3074  29.0  udfStrToMorse_3
;    4   2721  25.7  udfStrToMorse_4
;    5   3047  28.8  udfStrToMorse_5
; DateTime = 2010:12:23:22:08:06
; --------------------------------------------------;;;