Jump to content

Police Letters


standsolid
 Share

Recommended Posts

This is a script that will give you a nice GUI that you can enter text into and it will giv eyou the police/military letters back (ALPHA, BRAVO, CHARLIE, etc). I use this on support phone calls with users (reading passwords/urls), and I'm sure it could be useful elsewhere too.

I used a perl script from a site listed in the code to get the hash of police letters. i used that code in a perl script that I then based this auto-it script off of. I only have windows at work and don't wnat to install activestate.

It uses AutoIT GUI functions and the "hash" include code. You can get that include file here http://www.autoitscript.com/forum/index.ph...ic=1856&hl=hash

This is one of my first Auto-It scripts, and I am still learning...Auto-It is awesome.

When you have a hammer, everything looks like a nail.

;
;  alphabet hash based on http://www.xs4all.nl/~reinoud/perl/adduser.pl
;
#include <GUI_include.au3>
#include <hash.au3>
Opt("GUINotifyMode", 1)
Opt("TrayIconHide", 1)


$policeLetters = HashCreate("a|alpha:b|bravo:c|charlie:d|delta:e|echo:f|foxtrot:g|golf:h|hotel:i|india:j|juliet:k|kilo:l|lima:m|mike:n|november:o|oscar:p|papa:q|quebec:r|romeo:s|sierra:t|tango:u|uniform:v|victor:w|whiskey:x|xray:y|yankee:z|zulu:0|number zero:1|number one:2|number two:3|number three:4|number four:5|number five:6|number six:7|number seven:8|number eight:9|number nine: |space:.|dot", ":", "|")


$title = "Police Letter-i-fier"
GuiCreate ($title, 270)            
Opt("GuiCoordMode", 2)
GuiSetControl ("label", "Enter text to be police letter-i-fied", 6,6)
$nNormal = GuiSetControl ("input", "", -1,0) 
$nGo = GUISetControl( "button", "Go", 0,-1, 40,22)
;Opt("GuiCoordMode", 1)
$nPolice = GUISetControl( "edit", "", -262,8,260, 210)
;GUISetControlEx(-1, )
$nOk     = GUISetControl( "button", "Close", -1,0,260,25)




GuiShow ()

AdLibEnable("checkingChange")
WinWaitClose($title)    ; GuiWaitClose cannot be used to wait
AdlibDisable()

exit


;
; Dialog functionality.  Mostly not interactive, so...
;
Func checkingChange()

    $msg = GuiMsg()
    Select
    Case $msg = 0
      Exit    
    ;;;
    Case $msg = $nOk
        Exit  
    ;;;
    Case $msg = $nGo
        letterWriter($nPolice)
;;;
    EndSelect
EndFunc


Func letterWriter($editControl)
    $convString = GUIRead($nNormal)
    $spltString = StringSplit($convString, "")
    GUIWrite($nPolice,0,"")
    if $spltString[0] >= 1 then
  For $i = 1 To $spltString[0]
    
    if HashLookUp($policeLetters, $spltString[$i]) == "0" then 
    $letter = $spltString[$i]
    Else 
    if StringisUpper($spltString[$i]) Then 
      $letter = StringUpper(HashLookUp($policeLetters, $spltString[$i]))
    Else
      $letter = HashLookUp($policeLetters, $spltString[$i])
    EndIf
    EndIf
    GUIWrite($nPolice,0, $letter)
    if $i <> $spltString[0] Then GUIWrite($nPolice,0," - ")
    if $i / 4 == Round(($i / 4), 0) Then GUIWrite($nPolice,0, @CRLF)
    Next
  Endif
EndFunc

Use it and improve it as you wish.

Edited by standsolid
Link to comment
Share on other sites

This is cool .. lol

GOLF - UNIFORM - INDIA - _ - 
india - november - charlie - lima - 
uniform - delta - echo - dot - 
alpha - uniform - number three

is GUIConstants.au3

Edited by bobheart
Link to comment
Share on other sites

:D Excellent idea!

I thought I'd try to make the a (nonGUI) version that's as short as possible so here it is:

$list = "Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu"
Do
   $entry = InputBox("Phonetic Alphabet", "Enter phrase to translate, or leave blank to quit")
   $result = ""
   For $i = 1 to StringLen($entry)
      $result = $result & Substitute(StringMid($entry,$i,1))
   Next
   MsgBox(4096,"Translated", $result)
Until $entry = ""
Func Substitute($char)
   $start = StringInStr($list, StringUpper($char), 1);case-sensitive
   $end = StringInStr( StringTrimLeft($list,$start) , "," )
   If $start = 0 Then Return $char & ", "
   Return StringMid($list, $start, $end) & ", "
EndFunc
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Guest SigiS

why that complicated ?

how about this ?

$list = "Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu"
$list = stringsplit($list, ",")
Do
  $entry = InputBox("Phonetic Alphabet", "Enter phrase to translate, or leave blank to quit")
  $entry = StringUpper($entry)
  if $entry = "" Then ExitLoop
  $result = ""
  For $i = 1 to StringLen($entry)
     $j = asc(StringMid($entry,$i,1))-64
     if $j > 0 and $j <26 then $result = $result & $list[$j] & " - "
  Next
  $result = StringTrimRight($result , 3)
  MsgBox(4096,"Translated", $result)
Until 0

any suggestions?

Link to comment
Share on other sites

how about this ?

Nice use of string split :D Just make one change: $j <= 26

Here's an 11-line version that does not strip numbers:

$list = StringSplit("Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu", ",")
Do
   $entry = StringUpper(InputBox("Phonetic Alphabet", "Enter phrase to translate, or leave blank to quit"))
   $result = ""
   For $i = 1 to StringLen($entry)
      $j = Asc(StringMid($entry,$i,1))-64
      If $j > 0 and $j <= 26 Then $result = $result & $list[$j] & " - "
      If $j <= 0 or $j > 26 Then $result = $result & StringMid($entry,$i,1) & " - "
   Next
   MsgBox(4096,"Translated", StringTrimRight($result,3))
Until $entry = ""

You use if $entry = "" Then ExitLoop which is better, but it causes an extra line of code :huh2:

I could get my code down to 10 lines if removed and expanded $j... but the total amount of code would increase.

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Hi again: Eight lines if you drop number support and combine use InputBox for both input and output! :D

Dim $result, $list = StringSplit("Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu", ",")
Do
   $entry = StringUpper(InputBox("Phonetic Alphabet", "Enter phrase to translate.", StringTrimRight($result,3)))
   $result = ""
   For $i = 1 to StringLen($entry)
      If Asc(StringMid($entry,$i,1))-64 > 0 and Asc(StringMid($entry,$i,1))-64 <= 26 Then $result = $result & $list[Asc(StringMid($entry,$i,1))-64] & " - "
   Next
Until $entry = ""

If you remove looping, you can get down to five lines:

Dim $result, $list = StringSplit("Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu", ","), $entry = StringUpper(InputBox("Phonetic Alphabet", "Enter phrase to translate."))
For $i = 1 to StringLen($entry)
   If Asc(StringMid($entry,$i,1))-64 > 0 and Asc(StringMid($entry,$i,1))-64 <= 26 Then $result = $result & $list[Asc(StringMid($entry,$i,1))-64] & " - "
Next
MsgBox(4096,"Result", StringTrimRight($result,3) )
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Guest Guest_standsolid

@CyberSlug

I never even thought of using a list instead of a hash. That's awesome.

The reason I made it GUI was i wanted it to update the police letters as you typed (so I could be typing www.micro.... and read the results as I type) -- but I didn't succeed.

Link to comment
Share on other sites

if you drop number support and combine use InputBox for both input and output!

that's awesome, turns into some thing I'll use (just too lazy to go download other components) however, the main time I'm needing cop-talk is when I'm reading back serial numbers... think it'd be possible to just display the numbers in line with the cop-talk?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

What about this?

Func Phonetic($phrase)
   Local $list = StringSplit("Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Pap

a,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu", ",")
   Local $i, $m, $msg = "", $last = 0
   
   For $i = 1 To StringLen($phrase)
      $m = StringMid($phrase, $i, 1)
      If StringIsAlpha($m) Then
         If $last Then $msg = $msg & "-"
         $m = Asc(StringUpper($m)) - 64; Normalize the letters to first character.  "A" = Chr(65)
         $msg = $msg & $list[$m]
         $last = 1
      Else
         $msg = $msg & $m
         $last = 0
      EndIf
   Next
   Return $msg
EndFunc  ;==>Phonetic

While 1
   $k = InputBox("Translator", "Enter a string to be translated.", "", " M", -1, -1, -1, -1, 45)
   If @error Then;any error, including Cancel button and timeout
      ExitLoop
   Else
      MsgBox(0, "Translator:" & $k, Phonetic($k))
   EndIf
Wend

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Scite and Tidy. :D

I just used StringIsAlpha to check if the character is a letter. If so, determine the correct word to add to the message. Otherwise, put in the original character.

Edited by Nutster

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

don't know how you did it

I meant more the whole proccess of it. . . I'll pour over the script till I do get it... when it's not so late...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...