|
Perry Mowbray
|
 |
« Reply #2 on: April 13, 2007, 08:36:26 AM » |
|
Hi Ruffnekk: I wouldn't say I'm a brilliant coder, but I can often get things done (though it's often pretty ugly). Anyway, I was intrigued by your problem so had a bash. The following VBScript code works for me:  [ copy or print] Dim Morse(36, 3) Dim FoundLetters() Dim iLastFoundLetter iLastFoundLetter = -1 ReDim FoundLetters(1) Dim MorseCodeString MorseCodeString = "-..----..--..----." ' Fill Morse Alphabet Call FillMorse() ' Check the Morse String CheckMorseCodeString(1) ' Join Found Characters Dim strFoundCharacters strFoundCharacters = Join(FoundLetters , ", ") ' Count Found Characters for x = 0 to 35 if Morse(x , 2) > 0 then if Len(strCountCharacters) > 0 then strCountCharacters = strCountCharacters & ", " & Morse(x , 1) & "=" & Morse(x , 2) else strCountCharacters = Morse(x , 1) & "=" & Morse(x , 2) end if end if next if msgbox ( "Morse String: " & MorseCodeString & vbnewline & "Found: " & strFoundCharacters & vbnewline & vbnewline & "Copy to clipboard?", 4 , "Found Characters") = 6 Then Set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") strURL = objIE.document.parentwindow.clipboardData.setData("Text" , Replace(strFoundCharacters , ", " , vbnewline ) ) end if if msgbox ("Morse String: " & MorseCodeString & vbnewline & "Found: " & strCountCharacters & vbnewline & vbnewline & "Copy to clipboard?", 4 , "Count Characters") = 6 Then Set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") strURL = objIE.document.parentwindow.clipboardData.setData("Text" , Replace(strCountCharacters , ", " , vbnewline ) ) end if Sub CheckMorseCodeString( iStartHere ) Dim iWhatsLeft For iStart = iStartHere To Len(MorseCodeString) iWhatsLeft = Len(MorseCodeString) - iStart + 1 If iWhatsLeft > 7 then iWhatsLeft = 7 For iLength = 1 To iWhatsLeft CheckString( Mid(MorseCodeString , iStart , iLength)) Next Next End Sub Function CheckString(sString) For iCount = 0 to Ubound(Morse)-1 if sString = Morse(iCount , 0) then CheckString = True ' Add another found letter ReDim Preserve FoundLetters(Ubound(FoundLetters)+1) ' Add Found letter to Found Letters FoundLetters(ubound(FoundLetters)) = Morse(iCount, 1) ' Increase the Found Count by 1 Morse( iCount, 2) = Morse( iCount , 2) + 1 exit for else if len(Morse(iCount , 0 )) > len(sString) then exit for end if Next End Function Sub FillMorse() Dim x x = 0 Morse(x,0)="." Morse(x,1)="e" Morse(x,2)=0 x=x+1 Morse(x,0)="-" Morse(x,1)="t" Morse(x,2)=0 x=x+1 Morse(x,0)=".-" Morse(x,1)="a" Morse(x,2)=0 x=x+1 Morse(x,0)=".." Morse(x,1)="i" Morse(x,2)=0 x=x+1 Morse(x,0)="--" Morse(x,1)="m" Morse(x,2)=0 x=x+1 Morse(x,0)="-." Morse(x,1)="n" Morse(x,2)=0 x=x+1 Morse(x,0)="-.." Morse(x,1)="d" Morse(x,2)=0 x=x+1 Morse(x,0)="--." Morse(x,1)="g" Morse(x,2)=0 x=x+1 Morse(x,0)="-.-" Morse(x,1)="k" Morse(x,2)=0 x=x+1 Morse(x,0)="---" Morse(x,1)="o" Morse(x,2)=0 x=x+1 Morse(x,0)=".-." Morse(x,1)="r" Morse(x,2)=0 x=x+1 Morse(x,0)="..." Morse(x,1)="s" Morse(x,2)=0 x=x+1 Morse(x,0)="..-" Morse(x,1)="u" Morse(x,2)=0 x=x+1 Morse(x,0)=".--" Morse(x,1)="w" Morse(x,2)=0 x=x+1 Morse(x,0)="-..." Morse(x,1)="b" Morse(x,2)=0 x=x+1 Morse(x,0)="-.-." Morse(x,1)="c" Morse(x,2)=0 x=x+1 Morse(x,0)="...." Morse(x,1)="h" Morse(x,2)=0 x=x+1 Morse(x,0)=".---" Morse(x,1)="j" Morse(x,2)=0 x=x+1 Morse(x,0)="..-." Morse(x,1)="f" Morse(x,2)=0 x=x+1 Morse(x,0)=".-.." Morse(x,1)="l" Morse(x,2)=0 x=x+1 Morse(x,0)=".--." Morse(x,1)="p" Morse(x,2)=0 x=x+1 Morse(x,0)="--.-" Morse(x,1)="q" Morse(x,2)=0 x=x+1 Morse(x,0)="...-" Morse(x,1)="v" Morse(x,2)=0 x=x+1 Morse(x,0)="-..-" Morse(x,1)="x" Morse(x,2)=0 x=x+1 Morse(x,0)="-.--" Morse(x,1)="y" Morse(x,2)=0 x=x+1 Morse(x,0)="--.." Morse(x,1)="z" Morse(x,2)=0 x=x+1 Morse(x,0)=".----" Morse(x,1)="1" Morse(x,2)=0 x=x+1 Morse(x,0)="..---" Morse(x,1)="2" Morse(x,2)=0 x=x+1 Morse(x,0)="...--" Morse(x,1)="3" Morse(x,2)=0 x=x+1 Morse(x,0)="....-" Morse(x,1)="4" Morse(x,2)=0 x=x+1 Morse(x,0)="....." Morse(x,1)="5" Morse(x,2)=0 x=x+1 Morse(x,0)="-...." Morse(x,1)="6" Morse(x,2)=0 x=x+1 Morse(x,0)="--..." Morse(x,1)="7" Morse(x,2)=0 x=x+1 Morse(x,0)="---.." Morse(x,1)="8" Morse(x,2)=0 x=x+1 Morse(x,0)="----." Morse(x,1)="9" Morse(x,2)=0 x=x+1 Morse(x,0)="-----" Morse(x,1)="0" Morse(x,2)=0 End Sub Is that the sort of thing you meant??
|